38

这里的正确语法是什么?

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'
              ,16
              ,1
              ,(Select PromoStartTimestamp From @promo));
4

1 回答 1

64

您可以%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);
于 2012-04-05T17:09:43.253 回答