Re: Dynamic SQL Execution
From: exBK (exBK_at_discussions.microsoft.com)
Date: 11/12/04
- Next message: Alejandro Mesa: "Re: Select fails with "Arithmetic overflow" after indexing a decim"
- Previous message: Alejandro Mesa: "Re: Insert blank row after a group of records."
- In reply to: Adam Machanic: "Re: Dynamic SQL Execution"
- Next in thread: Adam Machanic: "Re: Dynamic SQL Execution"
- Reply: Adam Machanic: "Re: Dynamic SQL Execution"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 12 Nov 2004 08:54:44 -0800
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: Alejandro Mesa: "Re: Select fails with "Arithmetic overflow" after indexing a decim"
- Previous message: Alejandro Mesa: "Re: Insert blank row after a group of records."
- In reply to: Adam Machanic: "Re: Dynamic SQL Execution"
- Next in thread: Adam Machanic: "Re: Dynamic SQL Execution"
- Reply: Adam Machanic: "Re: Dynamic SQL Execution"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|