Re: dynamic sql question
From: Tim S (stahta01_at_juno.com)
Date: 11/12/04
- Next message: Anith Sen: "Re: EXEC(sqlstatement) Resultset usage"
- Previous message: Gert-Jan Strik: "Re: What is the wrong with this SQL?"
- In reply to: exBK: "dynamic sql question"
- Messages sorted by: [ date ] [ thread ]
Date: 12 Nov 2004 10:12:25 -0800
My best guess below
Tim S
EXECUTE sp_executesql @stmt = N'SELECT @rOUT = ' + QUOTENAME(@colName)
+ ' FROM tblName WHERE eid=@AID', @params = N'@rOUT VARCHAR(100)
OUTPUT, @AID VARCHAR(10)', @rOUT=@data OUTPUT, @AID=@empID
"exBK" <exBK@discussions.microsoft.com> wrote in message news:<0094DCB1-BC08-4664-8A23-1BB263D3EE12@microsoft.com>...
> I have a cursor where I loop through a set of employee_ids.
> While inside the cursor, I have a second set of cursor, which gets the
> column_name from information "information_schema.columns" for a given table.
> The problem I have run into in the following code is:
>
> EXECUTE sp_executesql
> @stmt = N'SELECT @rOUT = [@cName] FROM tblName WHERE eid=@AID',
> @params = N'@rOUT VARCHAR(100) OUTPUT, @cName VARCHAR(20), @AID VARCHAR(10)',
> @rOUT=@data OUTPUT, @cName=@colName, @AID=@empID
>
> I get the error Invalid column name '@cName'
>
> the @colName is coming from the second cursor, which I am not sure how to
> use it dynamically. i.e., I can't use it in a "SELECT" statement to get a
> value. Any tips are greatly appreciated. TIA.
- Next message: Anith Sen: "Re: EXEC(sqlstatement) Resultset usage"
- Previous message: Gert-Jan Strik: "Re: What is the wrong with this SQL?"
- In reply to: exBK: "dynamic sql question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|