1

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???

2

2 Answers 2

1

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'
Sign up to request clarification or add additional context in comments.

2 Comments

It's working for select statement,and what about print statement??
SELECT returns results as a table, and PRINT just outputs messages to the log. If you want to add a label, just put a string in front of the variable. For example, print N'Total # of female employees = ' + CAST(@TotalCount as nvarchar(10))
0

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.

1 Comment

Hi Kevin, for select statement it's working what about print statement.If I replace print instead of select I am getting an error. I wants to appear the column name in print statement as well.As I have attached the screen shot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.