SQL Server 2008:从一个SELECT查询中填充多个T-SQL变量?

时间:2010-09-29 14:29:18

标签: sql-server tsql sql-server-2008 sql

要使用查询中的值填充一个变量,我可以编写以下内容:

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)

我能写些什么?

1 个答案:

答案 0 :(得分:21)

SELECT TOP (1) @TargetID=ID, @TargetName=Name 
FROM @bigDataSet 
ORDER BY date DESC