Skip to content
Advertisement

How to insert records to temptable which has ;with command in sql?

I have created a temp table which I want to fill with records.

Here is my query:

Here I get table cst is Invalid .

Invalid object name ‘cst’.

What am I doing wrong in the above query?

Advertisement

Answer

Once your CTE aliased as cst has been used in the SELECT statement, it can’t be used again. This might be what you intended to do:

If you really need to run that select to check what is being returned, then run it on the side, but remove it when you actually use it in the insert.

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