Sep 16, 2013

Must pass parameter number 2 and subsequent parameters as '@name = value'. After the form '@name = value' has been used, all subsequent parameters must be passed in the form '@name = value'.


Suppose we have created a simple stored procedure uspDisplayData in sql server:

CREATE PROCEDURE uspDisplayData(
     @Param1 AS VARCHAR(100),
     @Param2 AS INT
)
AS
SELECT @Param1, @Param2

Now if we will execute this stored procedure:

EXECUTE dbo.uspDisplayData @Param1 = 'Sql Server',2

We will get error message like:

Must pass parameter number 2 and subsequent parameters as '@name = value'. After the form '@name = value' has been used, all subsequent parameters must be passed in the form '@name = value'.

Cause: If we want to use variable names while passing parameters to stored procedure then we must have to use variable in all the parameters.

Solution:

Correct ways to pass the parameters are:

EXECUTE dbo.uspDisplayData 'Sql Server',2

Or

EXECUTE dbo.uspDisplayData @Param1 = 'Sql Server',@Param2 = 2

Output:

(No column name)
(No column name)
Sql Server
2

No comments:

Post a Comment