Declare



DECLARE sets a variable to the value of an expression. The variable can then be used, with its @ prefix, in the statements that follow it in the same script.

round-pushpin Declares a number and uses it in a WHERE clause.
DECLARE @Language = 2
SELECT Text FROM WordList:Word WHERE LanguageId = @Language

round-pushpin Declares the result of an expression.
DECLARE @Pattern = 'Cat' + '%'
SELECT Text FROM WordList:Word WHERE Text LIKE @Pattern

round-pushpin Uses a variable in the field list.
DECLARE @Greeting = 'Hello'
SELECT @Greeting + ' ' + Text as Message FROM WordList:Word WHERE Id = 1

Client parameters

Parameters passed by an application through the client API are used the same way, for example WHERE Name = @Name. See Client.