Reputation: 22086
I have a stored procedure which is returning a integer value, but at the time of print I want to print “%” symbol.
declare @avg int
exec example @avg output
select @avg
It is giving only number like 80. But I want 80%
Upvotes: 1
Views: 3453
Reputation: 3205
It doesn't seem correct to try to solve this by modifying your Stored Procedure. Isn't there any way in which you can add the % symbol in the UI or when you are formatting whatever is supposed to be printed?
You can Cast or Convert an INT value into a VARCHAR using e.g. CAST(@avg as VARCHAR)
and thereby making it legal to perform string concatenation using the +
operator. This will of course also impact the return type of your sproc.
Upvotes: 5
Reputation: 10790
Well, since @avg is declared as int, you have to cast it before appending a character.
SELECT cast(@avg as varchar(5)) + '%'
Upvotes: 3
Reputation: 3106
Convert to string while printing
declare @avg int
set @avg = 80
select Convert(varchar(5),@avg) + '%'
or
print Convert(varchar(5),@avg) + '%'
I hope this help to u...
Upvotes: 3
Reputation: 55499
declare @avg int
exec example @avg output
select cast(@avg as nvarchar(10)) + '%'
Upvotes: 1