0

我被困在这个地方。我正在尝试在变量中获取单个行集值。

DECLARE @last_timestamp as varchar;
SET @last_timestamp = SELECT MAX(modify_timestamp) FROM dbo.table1
PRINT @last_timestamp

它返回以下错误

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'SELECT'.

Cursor 是解决此问题的唯一方法吗?任何帮助会有帮助吗?

4

3 回答 3

1
SELECT @last_timestamp := MAX(modify_timestamp) FROM dbo.table1

或者

SELECT MAX(modify_timestamp) INTO @last_timestamp FROM dbo.table1 

或者

SET @last_timestamp = (SELECT MAX(modify_timestamp) FROM dbo.table1)
于 2012-10-05T20:22:37.697 回答
0

尝试:

DECLARE @last_timestamp as varchar;
SELECT @last_timestamp  = MAX(modify_timestamp) FROM dbo.table1
PRINT @last_timestamp

或者

DECLARE @last_timestamp as varchar;
SET @last_timestamp  = (SELECT MAX(modify_timestamp) FROM dbo.table1)
PRINT @last_timestamp
于 2012-10-05T20:25:27.117 回答
0

SELECT您可以在语句周围放置括号

DECLARE @last_timestamp as varchar;
SET @last_timestamp = (SELECT MAX(modify_timestamp) FROM dbo.table1)
PRINT @last_timestamp
于 2012-10-05T20:25:04.840 回答