0
SELECT TOP 1 [FirstName], [LastName]
FROM [table]

DECLARE @firstName VARCHAR(25)

运行上面的查询后,我想将从查询中返回的 [FirstName] 分配给 @firstName。

我该怎么做呢?

4

3 回答 3

1
DECLARE @firstName VARCHAR(25) 

SELECT TOP 1 @firstName = [FirstName] FROM [table] 
于 2012-09-12T14:17:27.020 回答
0

像这样:

DECLARE @firstName VARCHAR(25), @LastName VARCHAR(25)

SELECT TOP 1 @firstName = [FirstName], @LastName = [LastName]
FROM [table]
于 2012-09-12T14:17:40.637 回答
0

用于SET从查询中分配值:

DECLARE @firstName VARCHAR(25)

SET @firstName = (SELECT TOP 1 [FirstName] FROM [table])
于 2012-09-12T14:17:43.403 回答