dbTalk Databases Forums  

return values from EXEC(string)

microsoft.public.sqlserver.programming microsoft.public.sqlserver.programming


Discuss return values from EXEC(string) in the microsoft.public.sqlserver.programming forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jo Inferis
 
Posts: n/a

Default return values from EXEC(string) - 12-17-2004 , 11:36 AM






Firstly, apologies if this it the wrong place to ask!

I have a stored procedure which builds some SQL in an nvarchar. I can, of
course execute this SQL with EXEC(@mySQL), but how do I access the recordset
that is returned *while still within the stored procedure*?

Basically the SQL returns a single value every time, but based on wildly
varying FROM and WHERE statements (hence why I can't use CASE statements).
I'd like to do something like @myvalue = EXEC(@mySQL), but of course this
doesn't work...

Any help would be greatly appreciated.

--
jo inferis



Reply With Quote
  #2  
Old   
Aaron [SQL Server MVP]
 
Posts: n/a

Default Re: return values from EXEC(string) - 12-17-2004 , 11:45 AM






http://www.aspfaq.com/2492

--
http://www.aspfaq.com/
(Reverse address to reply.)




"Jo Inferis" <jo (AT) inferis (DOT) NOSPAM.gotadsl.co.uk> wrote

Quote:
Firstly, apologies if this it the wrong place to ask!

I have a stored procedure which builds some SQL in an nvarchar. I can, of
course execute this SQL with EXEC(@mySQL), but how do I access the
recordset
that is returned *while still within the stored procedure*?

Basically the SQL returns a single value every time, but based on wildly
varying FROM and WHERE statements (hence why I can't use CASE statements).
I'd like to do something like @myvalue = EXEC(@mySQL), but of course this
doesn't work...

Any help would be greatly appreciated.

--
jo inferis





Reply With Quote
  #3  
Old   
Alejandro Mesa
 
Posts: n/a

Default RE: return values from EXEC(string) - 12-17-2004 , 11:47 AM



Use SP_EXECUTESQL instead.

Example:

use northwind
go

declare @i int
declare @sql nvarchar(4000)

set @sql = N'select @i = count(*) from dbo.orders where orderdate >
''19960101'' and orderdate < ''19970101'''

execute sp_executesql @sql, N'@i int output', @i = @i output

print @i



AMB


"Jo Inferis" wrote:

Quote:
Firstly, apologies if this it the wrong place to ask!

I have a stored procedure which builds some SQL in an nvarchar. I can, of
course execute this SQL with EXEC(@mySQL), but how do I access the recordset
that is returned *while still within the stored procedure*?

Basically the SQL returns a single value every time, but based on wildly
varying FROM and WHERE statements (hence why I can't use CASE statements).
I'd like to do something like @myvalue = EXEC(@mySQL), but of course this
doesn't work...

Any help would be greatly appreciated.

--
jo inferis




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.