Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@parameter = @parameter syntax (SQL Server)

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.

like image 757
Ginden Avatar asked Sep 14 '26 15:09

Ginden


2 Answers

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:

  1. The procedure expects @id and @name parameters
  2. There are two local variables with the same name in you calling module.

The code could maybe be more understandable, if it was written this way:

 exec dbo.get_name @id = @customerId, @name = @customerName output
like image 52
Marko Juvančič Avatar answered Sep 18 '26 18:09

Marko Juvančič


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.

like image 21
Hans Kesting Avatar answered Sep 18 '26 18:09

Hans Kesting



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!