简体   繁体   中英

Return a concatenated value from a SQL stored procedure

Please advise me to get the return value as 4/30 from a stored procedure. I have declared a stored procedure with one output parameter @result varchar(5) output and no input parameter, I have declared 3 variables inside a stored procedure say

declare @a float
declare @b float
declare @c varchar  

set @a=4
 set @b=30
set  @c=cast(@a as varchar)+'/'+cast(@b as varchar)

set @result=@c
return @result

The stored procedure executes and returns the return value as 4. But I need the return value to be 4/30. Is it possible to get 4/30 as return value? Please suggest me on the above...

Actually I want to set @a to a select query which returns a float number, and set @b to another select query which returns a float number .. but in the above sp just showed an example. Please advise me to get the return value as 4/30.

You need to specify a size for @c . Without size it will be varchar(1) .

declare @c varchar(5)

声明变量@c时,应指定length参数

declare @c varchar(5)

After writing down query in MS,the thing i clear about is that there is need to specify variable length of variable.....

declare @a int;
declare @b int;
declare @c varchar(5);
set @a=4;
set @b=30;
SET @c=cast(@a as varchar)+'/'+cast(@b as varchar)
select @c;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM