1

我在这里做错了什么?

Declare @starttimestamp datetime = getdate();
RAISERROR(N'Code not valid until %s', 16, 1, CAST(@starttimestamp AS VARCHAR));

产生一个错误说Incorrect syntax near 'CAST'.Incorrect syntax near '@starttimestamp'. Expecting SELECT or (

4

2 回答 2

1

您不能在 raiserror 命令中执行功能。首先将您的日期转换为字符串,如下所示:

Declare @starttimestamp datetime = getdate(),
        @TextDate  char(19)
select @TextDate = convert(char(19),@starttimestamp,120)

RAISERROR(N'Code not valid until %s', 16, 1, @TextDate)
于 2012-04-05T17:54:31.913 回答
0
Declare @starttimestamp varchar(20) = cast(getdate() as varchar(20)); 
RAISERROR(N'Code not valid until %s', 16, 1, @starttimestamp ); 
于 2012-04-05T17:54:23.240 回答