Concatenate Message In RAISERROR
sql, sql-server, sql-server-2008
Solution
You can use `%s` as a string substitution parameter in `RAISERROR`:
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);
Problem
What's the proper syntax here? ``` If (@timestamp < (Select PromoStartTimestamp From @promo)) RAISERROR('Code not valid until ' + (Select PromoStartTimestamp From @promo) ,16 ,1); ``` I've tried: ``` If (@timestamp < (Select PromoStartTimestamp From @promo)) RAISERROR(N'Code not valid until @starttimestamp' ,16 ,1 ,(Select PromoStartTimestamp From @promo)); ```