To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME News MS SQL Oracle DB2 Access MySQL PHP Scripts Books Links DBA Talk


Go Back   Database Journal Forums > Related Sites > SQL Course

SQL Course SQL Course > Ask questions about the lessons on SQL Course 1 and 2. If you have problems > with the interface, please post in the Feedback forum

Reply Post New Thread
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-23-2002, 03:31 PM
jduckwo jduckwo is offline
Junior Member
 
Join Date: Oct 2002
Posts: 1
Dyanmic SQL in Stored Proc

I am trying to get a return value from dynamically created SQL statement in a stored procedure so that the stored procedure can determine how to proceed. Any ideas on how to do this??

EXAMPLE CODE:
--------------------

CREATE PROCEDURE st_addHistory (@record_id VARCHAR(50))AS
DECLARE @strSQL VARCHAR(1024)
SELECT @strSQL = 'SELECT somefield FROM tblSomething WHERE id = ' + @record_id
EXEC(@strSQL)

/*I need the Value from [somefield] here so I can see if it has a value*/
If somefield = 'Test1' DO THIS
...do some other stuff
GO

--------------------
END CODE


Thanks for any help,
Jake
Reply With Quote
  #2  
Old 11-12-2002, 11:51 AM
sduggan sduggan is offline
Junior Member
 
Join Date: Nov 2002
Posts: 4
Jake,
Perhaps you need to approach the problem from a different angle?:

It looks like the only part of the sql that is dynamic is the record_id. If this is true then maybe make the sp look like:

---------- Sample Pseudo Code – Start
CREATE PROCEDURE st_addHistory (@record_id VARCHAR(50)) AS
-- Validate @record_id so that sp does not break ...

-- Declare and Initialise a variable for output of somefield
declare @ouptutvar as somefieldtype
set @ouptutvar = ‘’

-- do ‘dynamic sql’
select @ouptutvar
from tblSomeTable
where id = @record_id

-- use resultant output value
if @ouptutvar = <something1>
begin
<do something>
end
if @ouptutvar = <something2>
begin
<do something2>
end
---------- Sample Pseudo Code - End

Cheers sduggan …
Reply With Quote
Reply Post New Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:58 PM.


DatabaseJournal Recent Articles


 » Searching and Sorting Strings in Oracle

 » Preparing To Upgrade Access Tables to SQL ...

 » Sun Expands MySQL With Closed Source

 » Microsoft Demos New SQL Server Features at...

 » Wipro and Oracle Launch First Joint Innova...

Search Database Journal:
 





Acceptable Use Policy

JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.