我被困在这个地方。我试图在变量中获得单个行集值。
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是解决此问题的唯一方法。任何帮助都会有所帮助吗?
答案 0 :(得分: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)
答案 1 :(得分:0)
您可以在SELECT
语句
DECLARE @last_timestamp as varchar;
SET @last_timestamp = (SELECT MAX(modify_timestamp) FROM dbo.table1)
PRINT @last_timestamp
答案 2 :(得分: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