Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Stored procedure with an output parameter

             A Stored procedure with an output parameter

Table name:  [dbo].[Test_EmployeeTbl]

 ðŸ‘‰select * from [dbo].[Test_EmployeeTbl]



CREATE TABLE Test_EmployeeTbl (

[Id] [int] IDENTITY(1,1) NOT NULL,

[Name] [varchar](50) NOT NULL,

[Gender] [varchar](50) NOT NULL,

[Salary] [varchar](max) NOT NULL,

[City] [varchar](50) NOT NULL,

)



Create a procedure:


create procedure spGetEmployeesByGender

@Gender varchar(50),

@EmployeeCount int Output

as 

begin

Select @EmployeeCount = Count(Id) from Test_EmployeeTbl

where Gender = @Gender

end


Note:👉 Here:  @EmployeeCount  is output variable and @Gender is an input variable.

How to show the data of output parameter👇

Declare @TotalEmployee int

execute spGetEmployeesByGender 'male', @TotalEmployee Output

select @TotalEmployee


Note: make @TotalEmployee is a variable and catch a value of @EmployeeCount



























Column is not 👆 showing male but how to show 👇the column of male employee


Declare @TotalEmployee int
execute spGetEmployeesByGender 'male', @TotalEmployee Output

select @TotalEmployee as Male_Employees






Post a Comment

0 Comments