0

I have a procedure in which I have allowed variable number of arguments i.e

CREATE Procedure OutputProcedure
 @FirstName nvarchar(20) = null,
 @MiddleName nvarchar(20) = null, 
 @LastName nvarchar(20) = null, 
 @City nvarchar(20) = null,
 @AveragePercentage int out

AS
BEGIN
/*CODE*/
End

Now, I want to be able to count the number of arguments which were passed to the procedure inside of this procedure itself. How can I do this?

I found This but it takes the name of the procedure being checked for the arguments which I think should not be the case if I was to do count inside of the same procedure only.

Community
  • 1
  • 1

1 Answers1

2

You can do this inside the SP. Try this.

Declare @cnt int

select @cnt = case when @FirstName is not null then 1 else 0 End+
       case when @MiddleName is not null then 1 else 0 End+
       case when @LastName is not null then 1 else 0 End+
       case when @City is not null then 1 else 0 End 

Select @cnt
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172
  • So, Param_Count then should store the value,right? I try to select the value and SSMS does not see it .Where am I wrong? –  Jan 24 '15 at 11:03
  • @sim - If you want to store the count then `delcare` a variable and store the count in that variable. Updated check now – Pரதீப் Jan 24 '15 at 11:05