DYNAMIC SQL

  • hello all,

    I'm back with another question

    I need to do the following query as a dynamic

    query

    declare @value varchar(20)

    declare @columnname varchar(20)

    declare @sql

    set @columnname = 'F_CHAIN'

    @sql = select @value = @columnname from parts

    exec(@sql)

    print @value

    print @sql

    when I try this I get nothing back. any Ideas

    on how this should be done.

    Thanks again for all the help

    cheers

    Randy

  • Its out of scope. You can use sp_executesql and do a bit of tricky code to return an output parameter (sample code somewhere here on the site!),or you can write the result out to either a permanent table or a global temp table, then read it when you return from the exec().

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

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

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