如何给 SQL 变量赋值
How to assign value to SQL variable
我有 SQL 代码,我在其中将嵌套查询的输出分配给一个变量,但在 )
附近出现语法不正确的错误
代码如下:
set @MAX_CNT =(select coun from (select MAX(SEQ) Coun from (
SELECT ROW_NUMBER()OVER(ORDER BY COUNTRY)SEQ,* FROM #TEMP1
)xx)y)
错误:
Msg 102, Level 15, State 1, Line 53
Incorrect syntax near ')'.
不确定是什么问题
set @MAX_CNT =(select coun from (select MAX(SEQ) Coun from (
SELECT ROW_NUMBER()OVER(ORDER BY COUNTRY)SEQ,* FROM #TEMP1
)xx)y)
应该给变量赋值。
你为什么不直接写这个?
select @MAX_CNT = count(*)
from #temp1;
不需要使用 window 聚合函数。
set @MAX_CNT = (select MAX(SEQ) Coun from
(
SELECT ROW_NUMBER()OVER(ORDER BY id)SEQ, * FROM users
) xx)
我有 SQL 代码,我在其中将嵌套查询的输出分配给一个变量,但在 )
附近出现语法不正确的错误代码如下:
set @MAX_CNT =(select coun from (select MAX(SEQ) Coun from (
SELECT ROW_NUMBER()OVER(ORDER BY COUNTRY)SEQ,* FROM #TEMP1
)xx)y)
错误:
Msg 102, Level 15, State 1, Line 53
Incorrect syntax near ')'.
不确定是什么问题
set @MAX_CNT =(select coun from (select MAX(SEQ) Coun from (
SELECT ROW_NUMBER()OVER(ORDER BY COUNTRY)SEQ,* FROM #TEMP1
)xx)y)
应该给变量赋值。
你为什么不直接写这个?
select @MAX_CNT = count(*)
from #temp1;
不需要使用 window 聚合函数。
set @MAX_CNT = (select MAX(SEQ) Coun from
(
SELECT ROW_NUMBER()OVER(ORDER BY id)SEQ, * FROM users
) xx)