sql server - SQL 2008 R2 CTE syntax error in a SELECT statement -
this question based on previous question
sql server 2008 r2, select 1 value of column each distinct value of column
about cte on sql server 2008.
my_cte(id_num, rn) ( select name, rn = row_number() on (partition a.name order newid()) my_table ) select id_num my_cte rn = 1 insert #temp_table select a.address another_table a, id_num my_cte -- here, got error!!!
why got error: incorrect syntax near keyword 'from'.
i need new table 1 column another_table , 1 column my_cte.
e.g.
address (from another_table) id_num (from my_cte) city_1 65 city_1 36 city_2 65 city_2 36 city_3 65 city_3 36
what kinds of join should use above table each address associated id_num cte ? suppose id_num has 65 , 36 2 values. my_cte has no column of address.
any appreciated.
a cte can used in statement directly after it. after select id_num my_cte rn = 1
, cte no longer exists.
Comments
Post a Comment