我只是假设我可以在SQL Server 2008中的set query
语句中添加WITH
。
所以我写了几行代码:
with temp as
(
SELECT row_number() OVER (ORDER BY [ShareItems].ItemId) AS Row, ItemId FROM [ShareItems]
)
set @row = ItemId //<---error
但我收到上述错误,但如果使用select
关键字WITH
语句,则没有错误???
with temp as
(
SELECT
row_number() OVER (ORDER BY [ShareItems].ItemId) AS Row, ItemId
FROM [ShareItems]
)
SELECT ItemId
FROM temp //<--- OK (no error)
有什么建议吗?
答案 0 :(得分:2)
尝试这种方式:
with temp as
(
SELECT row_number() OVER (ORDER BY [ShareItems].ItemId) AS Row, ItemId
FROM [ShareItems]
)
select @row = ItemId from temp
答案 1 :(得分:2)
试试这个:
with temp as
(
SELECT row_number() OVER (ORDER BY [ShareItems].ItemId) AS Row, ItemId FROM [ShareItems]
)
SELECT @row = ItemId FROM temp