When a SELECT assigns values ββto variables, all fields in the SELECT must be assigned to a local variable.
Change your SPROC to
CREATE PROCEDURE getCustomer ( @CustomerId int OUTPUT ) AS BEGIN DECLARE @FirstName VARCHAR(50) DECLARE @LastName VARCHAR(50) SELECT @CustomerId=CustomerId, @FirstName = FirstName, @LastName =LastName FROM Customers
You do not need to use these variables, but they must be assigned in this way.
Your BEST option is to remove the fields. If they are not needed, do not bother to choose them.
[EDIT] to reply to your comment
So, you can do what you want to do by dividing the variable assignment and selecting other fields as follows:
CREATE PROCEDURE getCustomer ( @CustomerId int OUTPUT ) AS BEGIN SELECT @CustomerId=CustomerId FROM Customers SELECT FirstName, LastName, {A_BUNCH_OF_OTHER_FIELDS} FROM Customers
This will allow you to get your output parameter and select all other data without the need to define parameters for each field. You should weigh ease of use (without having to define many local vars) compared to performance (to run two operators, not one). It seems a little strange to me.
I was not entirely clear if you needed other values ββfrom GetCustomer sproc available to you in getCustomer_and_more. If yes, then yes, you will need to define OUTPUT parameters for each value you need.
source share