July 4, 2009 at 5:22 am
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.
July 4, 2009 at 5:31 am
what are the data types of b and c and what is the expected output?
July 6, 2009 at 8:31 am
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
Consultant - Straight Path Solutions
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
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy