dbTalk Databases Forums  

Dynamically construct and execute SQL in StoredProcedure

mailing.database.mysql mailing.database.mysql


Discuss Dynamically construct and execute SQL in StoredProcedure in the mailing.database.mysql forum.



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

Default Dynamically construct and execute SQL in StoredProcedure - 04-24-2006 , 08:31 AM






Hey!

I need to dynamically create an SQL statement within a MySQL 5.0.20
stored procedure.

-- PSEUDO CODE
create procedure DynSQLTest
(
in sTable varchar(45)
)
begin
declare sSQL varchar(45);

select Concat('select * from ',sTable,' where ...) into sSQL;

EXECUTESQL(sSQL);
end;

Is there a possibility to construct the SQL in a varchar and then
execute it? I spent some time googling but did not find anything.

Thank you for any help!

Fred

Reply With Quote
  #2  
Old   
Bill Karwin
 
Posts: n/a

Default Re: Dynamically construct and execute SQL in StoredProcedure - 04-24-2006 , 02:14 PM






Fred wrote:
Quote:
Is there a possibility to construct the SQL in a varchar and then
execute it? I spent some time googling but did not find anything.
See here:
http://dev.mysql.com/doc/refman/5.0/en/sqlps.html

You can do this in stored procedures. See example in this article:
http://dev.mysql.com/tech-resources/...toredproc.html

Regards,
Bill K.


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.