Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Concatenation Expand / Collapse
Author
Message
Posted Saturday, July 4, 2009 5:22 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, August 23, 2013 7:44 AM
Points: 40, Visits: 68

If my SP has the following parameters

a="hyderabad" string

b=10.145

c=a+b

I want my storedprocedure to return the value of c?

is it possible to do so.
Post #747186
Posted Saturday, July 4, 2009 5:31 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, September 15, 2014 2:38 AM
Points: 2,223, Visits: 3,647
what are the data types of b and c and what is the expected output?





Pradeep Singh
Post #747191
Posted Saturday, July 4, 2009 6:49 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, March 24, 2014 1:16 AM
Points: 346, Visits: 412
IF I have defined right datatypes then

declare @a varchar(100)
declare @b float
declare @c varchar(max)
select @a ='hyderabad'
select @b= 10.145

select @c=@a + cast(@b as varchar(max))

print @c
Post #747198
Posted Monday, July 6, 2009 8:31 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:06 AM
Points: 10,193, Visits: 13,118
There are 2 ways to return a single value from a stored procedure, as a resultset and as an output parameter and the recommended method would to use an output parameter. Here's are examples the first being returning the value a s a resultset and the second as an output parameter

Create Procedure variable_as_result_set 
AS

SET NOCOUNT ON

declare @a varchar(100)
declare @b float
declare @c varchar(max)

select @a ='hyderabad'
select @b= 10.145

select @c=@a + cast(@b as varchar(max))

Select @c AS C

Return

Alter Procedure variable_as_outputparameter
(
@c VARCHAR(MAX) OUTPUT
)
AS

SET NOCOUNT ON

declare @a varchar(100)
declare @b float

select @a ='hyderabad'
select @b= 10.145

select @c=@a + cast(@b as varchar(max))

RETURN

GO
-- Example call of procedure using output paramter
DECLARE @output_param VARCHAR(MAX)

Exec variable_as_outputparameter @c = @output_param OUTPUT

SELECT @output_param





Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #747783
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse