Retrieve data into Local variable Through dynamic Query

  • Hi,

    In a Stored PROC I have a query which retrieves value into a local variable.

    Now the query has be converted into Dynamic.

    This is causing a problem.

    I am not able to retreive the value from dynamic query into variable.

    Ex: Select @Variable=Name FROM Employee

    The SELECT Clause needs to be converted into Dynamic,

    and retreive the value into @Variable. Is This is Posssible in SQL2000?

    NOTE: Retreiving the value into variable is important as it is used in other dynamic queries

    Thanks and Regards

    Chethan!!

  • Hi,

    Bellow is the code to get the return value from dyanamic SQL

    DECLARE @SQLString NVARCHAR(500)

    , @ParmDefinition NVARCHAR(500)

    , @Lastlname varchar(30)

    SET @SQLString = N' SELECT @LastlnameOUT = Name FROM Employee '                    

    SET @ParmDefinition = N'@LastlnameOUT varchar(30) OUTPUT'

    EXECUTE sp_executesql @SQLString, @ParmDefinition, @LastlnameOUT=@Lastlname OUTPUT

    SELECT @Lastlname

    Hope this will slove your problem

    cheers

  • Hi,

    Thank You 🙂

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

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