Concatenation

  • 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.

  • what are the data types of b and c and what is the expected output?



    Pradeep Singh

  • IF I have defined right datatypes then

    declare @a varchar(100)

    declare @b-2 float

    declare @C varchar(max)

    select @a ='hyderabad'

    select @b-2= 10.145

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

    print @C

  • 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-2 float

    declare @C varchar(max)

    select @a ='hyderabad'

    select @b-2= 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-2 float

    select @a ='hyderabad'

    select @b-2= 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

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply