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));
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);
%s
but you cannot use expressions (CAST) in the RAISERROR parameters. It has to be isntead RAISERROR(N'Code not valid until %s',16 ,1 ,@PromoStartTimestampCastedToString));
Remus Rusanu 2012-04-05 17:34
Cast(@promostarttimestamp as varchar)
sayingIncorrect syntax near 'Cast'. Expecting Select or (
or when I don'tCast
I getCannot specify datetime data type (parameter 4) as a substitution parameter.
Greg 2012-04-05 17:21