Naresh AR
Naresh AR

Reputation: 79

Stored procedure:Column name is not appearing while execute output parameters

I have created one stored procedure which is output parameters.

create proc sp_withoutputparameter
@Gender nvarchar(50),
@employeecount int output
as
begin
select @employeecount=count(id) from temployee where gender=@Gender
end


declare @Totalcount int 
execute sp_withoutputparameter @employeecount=@Totalcount  out,@Gender='Female' 
print @Totalcount

execute sp_withoutputparameter @employeecount=@Totalcount  out,@Gender='Female' 
select @Totalcount 

Screen shot 1 After executing the above queries. I am getting the results as showed in an attachments Screen shot 2 On both queries I were used print and select in both results I am not getting a column name.

Please help me on this issue and what should I need do an amendments in an query for appear the column name???

Upvotes: 1

Views: 887

Answers (2)

Kevin Bott
Kevin Bott

Reputation: 733

Looks like SQL Server, not MySQL, correct? Since you're selecting/printing a variable, it doesn't have a "column" name to put in the header. Have you tried:

select @TotalCount as TotalCount

The print command doesn't have a header, nor should it. It's meant to print a user defined message. https://learn.microsoft.com/en-us/sql/t-sql/language-elements/print-transact-sql

You could do...

print '@totalCount'
print '------------'
print @totalCount

That's how you would get a header with TSQL print statement.

Upvotes: 0

Ken
Ken

Reputation: 312

Since you're just outputting the variable as result, it won't have a column name. If you want to add one, just use an alias.

select @TotalCount as 'Total # of Female Employees'

Upvotes: 1

Related Questions