November 11, 2018 at 7:03 pm
After the CREATE PROCEDURE line, the next line defines a parameter variable. Why isn't the DECLARE keyword used here? Starting on line 5, when other variables are declared, the keyword DECLARE is used.
November 11, 2018 at 7:29 pm
That's how input parameters are declared. That's just how T-SQL works.
November 12, 2018 at 5:54 am
DECLARE is for creating local variables. These are different from parameters. Both start with @, but are treated differently within the engine, therefore different mechanisms for definition.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
November 12, 2018 at 12:19 pm
They may look the same, but there are more differences than just leaving out the word DECLARE.
Parameter declarations can have the attributes OUTPUT, READONLY, and VARYING; local variables cannot.
A variable declaration with a value (@p1 INT = 123 ) will always initialize the variable to that value. For a parameter, that syntax is a default value and makes the parameter optional. The value in the parameter declaration is only used if the parameter is omitted from the EXEC statement.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply