I am using SQL server 2012. I have three CTEs defined in a row as shown below:
;WITH X_CTE (A, B, C, D)
AS (
...
)
,
Y_CTE (A, B, C, D)
AS (
...
)
,
Z_CTE (A, B, C, D)
AS (
...
)
Then, I insert these CTEs into a table, whose schema is defined and matches that of the CTEs
INSERT INTO MyTable SELECT * FROM X_CTE
INSERT INTO MyTable SELECT * FROM Y_CTE
INSERT INTO MyTable SELECT * FROM Z_CTE
I am getting a 'Invalid object name' error for the CTEs in the three INSERT INTO statements. In fact, I get the same errors with SELECT statements:
SELECT * FROM X_CTE
SELECT * FROM Y_CTE
SELECT * FROM Z_CTE
Would you please point out what is wrong here?
Thanks
-Rohan.