我有以下查詢:如何將sql查詢的結果存儲在變量中?
with cte as
(SELECT top 10 [1],[2]
FROM [tbl_B] where [2] > '2000-01-01' and Status_7 = 0 and Status_8 = 1
ORDER BY [2])
,
CTE1 AS
(select [1], row_number() over (order by [2]) as rn
from CTE
)
select [1] from CTE1 where rn = '10'
我怎麼能放到一個變量此將其與另一個查詢結果? 如果我使用set @ 123 =(上面的查詢)它會給出錯誤。
作爲一個小紙條,而'SET @ 123 ='會「爆炸」,如果有多於一行,'SELECT @ 123 ='將毫無問題地執行並且放入最後一行的值。 – xanatos