-2

关键字“SELECT”附近的语法不正确...下面的代码生成错误...

DECLARE @A VARCHAR(12)
SET @A = SELECT TOP 1 MBR_ID FROM MBR_IDS ORDER BY NEWID()
SELECT @A 
4

2 回答 2

5

作为 JoeFletch 的好答案的替代方法,您可以使用括号()在标量上下文中评估查询:

SET @A = (SELECT TOP 1 MBR_ID FROM MBR_IDS ORDER BY NEWID())
于 2013-07-27T10:54:49.403 回答
4

你需要重组你的SELECT陈述。

DECLARE @A VARCHAR(12)
SELECT TOP 1 @A = MBR_ID FROM MBR_IDS ORDER BY NEWID()
SELECT @A 
于 2013-07-27T10:44:49.693 回答