1

我只是假设我可以在 SQL Server 2008 中放置一个set queryinsideWITH语句。

于是我写了几行代码:

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)

有什么建议吗?

4

2 回答 2

2

试试这个方法:

with temp as   
(
  SELECT row_number() OVER (ORDER BY [ShareItems].ItemId) AS Row, ItemId 
  FROM [ShareItems]
)

select  @row = ItemId from temp 
于 2013-05-09T13:11:26.240 回答
2

尝试这个:

with temp as   
    (
        SELECT row_number() OVER (ORDER BY [ShareItems].ItemId) AS Row, ItemId FROM [ShareItems]
    )
SELECT @row = ItemId FROM temp
于 2013-05-09T13:11:45.860 回答