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 に答える