要使用查询中的值填充一个变量,我可以编写以下内容:
SET @TargetID = (SELECT TOP 1 ID FROM @bigDataSet ORDER BY date DESC)
从此查询填充多个变量,例如。类似的东西:
SET (@TargetID, @TargetName) = ....(SELECT TOP 1 ID, [Name] FROM @bigDataSet ORDER BY date DESC)
我能写些什么?
答案 0 :(得分:21)
SELECT TOP (1) @TargetID=ID, @TargetName=Name
FROM @bigDataSet
ORDER BY date DESC