题 SQL Server 2008:从一个SELECT查询中填充多个T-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)

我能写什么?


14
2017-09-29 14:29


起源




答案:


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

21
2017-09-29 14:30



感谢你及时的答复。 - thomaspaulb