Skip to content
Advertisement

SQL – How to use a value from INSERTed table

I am trying to insert a new location record in my db … and then reuse the value of the newly created id in a select statement’s where clause later on. But I’m getting a syntax error.

Code:

The error is “Must declare scalar variable” and it dies on there WHERE clause in the SELECT statement.

I also tried something like this:

But that doesn’t work either. Any tips would be appreciated.

Advertisement

Answer

Add a GO statement just before -- MUCH LATER IN THE SQL CODE:

This will send the above statements to the server.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement