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));
According to the Differences Between RAISERROR and THROW in Sql Server: Both RAISERROR and THROW statements are used to raise an error in Sql Server. The journey of RAISERROR started from Sql Server 7.0; whereas the journey of the THROW statement has just began with Sql Server 2012.
RAISERROR can either reference a user-defined message stored in the sys. messages catalog view, or build a message dynamically. The message is returned as a server error message to the calling application or to an associated CATCH block of a TRY... CATCH construct.
Is an integer from 0 through 255. Negative values default to 1. Values larger than 255 should not be used. If the same user-defined error is raised at multiple locations, using a unique state number for each location can help find which section of code is raising the errors.
RAISERROR is a SQL Server error handling statement that generates an error message and initiates error processing. RAISERROR can either reference a user-defined message that is stored in the sys. messages catalog view or it can build a message dynamically.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With