SQL 在 RAISERROR 中连接消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10032914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 15:13:02 来源:igfitidea点击:
Concatenate Message In RAISERROR
提问by Greg
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));
回答by Michael Fredrickson
You can use %s
as a string substitution parameter in RAISERROR
:
您可以%s
在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);