Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding variable in Raise Error
Message
De
22/03/2011 12:12:06
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01504519
Message ID:
01504527
Vues:
27
>The simplest way to answer this question is to check BOL for Raiserror. It clearly states how to use parameters (C++ style) in the string.

I see that the only way to use the variable inside the string as is is to have only the variable. Thus, we have to define the variable entirely at first such as:
DECLARE @Time char(40)

SET @Time='This is the time '+convert(varchar,datepart(hour,getdate()))+':'+
 RIGHT(REPLICATE('0',2)+convert(varchar,datepart(minute,getdate())),2)+':'+
 RIGHT(REPLICATE('0',2)+convert(varchar,datepart(second,getdate())),2)

Raiserror(@Time,0,1) With Nowait
But, the following would not work which I find quite sad:
DECLARE @Time char(40)

SET @Time=convert(varchar,datepart(hour,getdate()))+':'+
 RIGHT(REPLICATE('0',2)+convert(varchar,datepart(minute,getdate())),2)+':'+
 RIGHT(REPLICATE('0',2)+convert(varchar,datepart(second,getdate())),2)

Raiserror('This is the time '+@Time,0,1) With Nowait
So, as I mentioned in the other message, if I wish to use that kind of approach, I then have to use the additional parameters supported by the Raiseerror() to include my variable such as:
DECLARE @Time char(40)

SET @Time=convert(varchar,datepart(hour,getdate()))+':'+
 RIGHT(REPLICATE('0',2)+convert(varchar,datepart(minute,getdate())),2)+':'+
 RIGHT(REPLICATE('0',2)+convert(varchar,datepart(second,getdate())),2)

Raiserror('This is the time %s',0,1,@Time) With Nowait
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform