这里的正确语法是什么?
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',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',@PromoStartTimestampString);