Re: Dynamic SQL Execution
From: Adam Machanic (amachanic_at_hotmail._removetoemail_.com)
Date: 11/12/04
- Next message: Anith Sen: "Re: csv Question"
- Previous message: Ram Kumar Koditala: "What is the wrong with this SQL?"
- In reply to: exBK: "Re: Dynamic SQL Execution"
- Next in thread: exBK: "Re: Dynamic SQL Execution"
- Reply: exBK: "Re: Dynamic SQL Execution"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 12 Nov 2004 11:59:05 -0500
Declare @sql as NVARCHAR. Also, you'll have to use the N' on the second
parameter as well (or use another NVARCHAR variable); I forgot to put it
there too.
-- Adam Machanic SQL Server MVP http://www.sqljunkies.com/weblog/amachanic -- "exBK" <exBK@discussions.microsoft.com> wrote in message news:DBE70382-3298-4AF6-B3BE-BAB0236EA3AE@microsoft.com... > Thank you so much for your reply. I have been trying exactly the same thing > ... my only problem is, the string: > 'SELECT @rOUT =[114x] FROM tblName WHERE eid=100' > is assigned to a variable each time within my cursror loop. In otherwords, > I have a: > SET @sql = 'SELECT @rOUT =[' + @cName + '] FROM tbl WHERE eid=' + @eID > and when I print my @sql, I get > 'SELECT @rOUT =[114x] FROM tblName WHERE eid=100' > > so when I use > sp_executesql N@sql, > '@rOUT (datatype) OUTPUT', > @rOUT OUTPUT > I don't get erors following: > * if I use N@sql .. it says "Incorrect syntax near 'N@sql'" > * if I use @sql .. it says "Procedure expects parameter '@statement' of > type 'ntext/nchar/nvarchar'" > > Not sure what I am doing wrong...TIA for your time. > > "Adam Machanic" wrote: > > > Use sp_executesql with an OUTPUT parameter: > > > > declare @rOUT (datatype) > > > > sp_executesql N'SELECT @rOUT =[114x] FROM tblName WHERE eid=100', > > '@rOUT (datatype) OUTPUT', > > @rOUT OUTPUT > > > > -- > > Adam Machanic > > SQL Server MVP > > http://www.sqljunkies.com/weblog/amachanic > > -- > > > > > > "exBK" <exBK@discussions.microsoft.com> wrote in message > > news:B5A0D99D-5FF6-46B7-A2BD-72EF93FC560E@microsoft.com... > > > I asked a similar question yesterday but still not sure how to move on .. > > > hence posting it agin: > > > > > > In a cursor, as I loop through, I create a dynamic SQL each time. > > > My dynamic SQL looks something like this: > > > > > > SELECT @rOUT =[114x] FROM tblName WHERE eid=100 > > > i.e, the above is assigned to a variable and when I print the variable, I > > > get the statement. > > > I am interested in getting the value for @rOUT so that I can use it in an > > > insert statment within the cursor's loop. I am not sure how to achieve > > this. > > > Any tips are appreciated. TIA. > > > > > > > > > > > >
- Next message: Anith Sen: "Re: csv Question"
- Previous message: Ram Kumar Koditala: "What is the wrong with this SQL?"
- In reply to: exBK: "Re: Dynamic SQL Execution"
- Next in thread: exBK: "Re: Dynamic SQL Execution"
- Reply: exBK: "Re: Dynamic SQL Execution"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|