标签: sql-server
我需要从表中选择一个字段并从某个值中计算出来。像这样:
DECLARE @n AS INT SET @n = 1111 SELECT F, @n = @n + 1 FROM MYTABLE
有可能吗?
答案 0 :(得分:2)
您无法将变量赋值与行选择相结合。您可以使用ROW_NUMBER代替
Declare @n int= 1111 Select ID, @n + ROW_NUMBER() Over (Order by ID) from aTable