SELECT TOP 1 [FirstName], [LastName]
FROM [table]
DECLARE @firstName VARCHAR(25)
运行上面的查询后,我想将从查询中返回的 [FirstName] 分配给 @firstName。
我该怎么做呢?
DECLARE @firstName VARCHAR(25)
SELECT TOP 1 @firstName = [FirstName] FROM [table]
像这样:
DECLARE @firstName VARCHAR(25), @LastName VARCHAR(25)
SELECT TOP 1 @firstName = [FirstName], @LastName = [LastName]
FROM [table]
用于SET
从查询中分配值:
DECLARE @firstName VARCHAR(25)
SET @firstName = (SELECT TOP 1 [FirstName] FROM [table])