Reputation: 5316
I have found this code in my job:
exec dbo.get_name @id = @id, @name = @name output
What does it mean? I couldn't find any examples using this syntax nor any information on Microsoft pages.
Upvotes: 2
Views: 4002
Reputation: 5890
When executing a storedprocedure, parameters can be passed in a different order than defined in the procedure. You have to use @parameterName
to tell which parameter is passed at which position.
There are two separate things in your code:
@id
and @name
parameters The code could maybe be more understandable, if it was written this way:
exec dbo.get_name @id = @customerId, @name = @customerName output
Upvotes: 6
Reputation: 2254
the person who wrote that code used local variables with the same name of the stored procedure parameters.
you will find somewhere in that code the declaration of these local variables:
declare @id int;
declare @name varchar(50);
.
.
[some more code here]
.
.
.
exec dbo.get_name @id = @id, @name = @name output
Upvotes: 2
Reputation: 37053
Here's what it means
exec dbo.get_name
- Execute a stored procedure names get_name@id = @id
- You proc accepts @id parameter and before calling this proc you must have defined a variable called @id and asssigned some value to it. So that value you are passing to the proc.@name = @name output
- Same as above except that the value in @name would be modified and you would get the value of @name post executing the proc as output. This of it as a return value from procedure post execution.Details about the same are here
Upvotes: 1
Reputation: 2617
That means that the dbo.get_name stored procedure is executed and @id = @id means you pass @id local value to @id input parameter and @name = @name means you want the output parameter @name to assign the output value to the local variable @name.
Upvotes: 1
Reputation: 39329
In @id = @id
, the first @id is a named parameter for the dbo.get_name
stored procedure.
The second @id is a local variable that supplies the value for the parameter.
Upvotes: 4