这里正确的语法是什么?
If (@timestamp < (Select PromoStartTimestamp From @promo))
RAISERROR('Code not valid until ' + (Select PromoStartTimestamp From @promo)
,16
,1);
我已经尝试过:
If (@timestamp < (Select PromoStartTimestamp From @promo))
RAISERROR(N'Code not valid until @starttimestamp'
,16
,1
,(Select PromoStartTimestamp From @promo));
最佳答案
您可以在 RAISERROR
中使用 %s
作为字符串替换参数:
DECLARE @PromoStartTimestamp DATETIME
DECLARE @PromoStartTimestampString VARCHAR(50)
SELECT @PromoStartTimestamp = PromoStartTimestamp From @promo
SELECT @PromoStartTimestampString = CAST(@PromoStartTimestamp AS VARCHAR)
If (@timestamp < @PromoStartTimestamp)
RAISERROR(N'Code not valid until %s'
,16
,1
,@PromoStartTimestampString);
关于sql - 连接 RAISERROR 中的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10032914/