473,385 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dynamic SQL in MySQL

Is it possible to create Dynamic SQL queries in MySQL, like in SQL Server?
i.e., the EXECUTE command or sp_executesql stored procedure in SQL Server.

TIA
Jul 23 '05 #1
7 8367
Michael C# wrote:
Is it possible to create Dynamic SQL queries in MySQL, like in SQL Server?
i.e., the EXECUTE command or sp_executesql stored procedure in SQL Server.


Do you mean in general, or specifically in the MySQL stored procedure
language?

I regularly build SQL statements as strings in application code (Perl,
PHP, Java, ASP, etc.).

But I can't find any mention in the MySQL 5.0 stored procedure language
documentation of this capability in stored procedures. I am not aware
that the ANSI/ISO SQL3 "Persistent Stored Modules" standard includes
this functionality, and that is the model on which MySQL based their
stored procedure language.

So no, AFAICT this is not supported in MySQL. It's an extension to the
SQL standard, implemented in a proprietary way by Microsoft and perhaps
some other vendors.

Regards,
Bill K.
Jul 23 '05 #2
Thanks Bill. Yeah, it all has to be done server-side in this case.

I was trying to convert some MS SQL code over to MySQL - specifically, some
dynamic SQL code that generates "pivot-table" type queries. Anyone have any
ideas on how that might be possible?

Thanks,
Michael C

"Bill Karwin" <bi**@karwin.com> wrote in message
news:ct*********@enews4.newsguy.com...
Michael C# wrote:
Is it possible to create Dynamic SQL queries in MySQL, like in SQL
Server? i.e., the EXECUTE command or sp_executesql stored procedure in
SQL Server.


Do you mean in general, or specifically in the MySQL stored procedure
language?

I regularly build SQL statements as strings in application code (Perl,
PHP, Java, ASP, etc.).

But I can't find any mention in the MySQL 5.0 stored procedure language
documentation of this capability in stored procedures. I am not aware
that the ANSI/ISO SQL3 "Persistent Stored Modules" standard includes this
functionality, and that is the model on which MySQL based their stored
procedure language.

So no, AFAICT this is not supported in MySQL. It's an extension to the
SQL standard, implemented in a proprietary way by Microsoft and perhaps
some other vendors.

Regards,
Bill K.

Jul 23 '05 #3
I'm actually trying to do a "Cross-tab" type query. Sorry about the mix-up.
Any ideas?

Thanks,
Michael C.

"Bill Karwin" <bi**@karwin.com> wrote in message
news:ct*********@enews4.newsguy.com...
Michael C# wrote:
Is it possible to create Dynamic SQL queries in MySQL, like in SQL
Server? i.e., the EXECUTE command or sp_executesql stored procedure in
SQL Server.


Do you mean in general, or specifically in the MySQL stored procedure
language?

I regularly build SQL statements as strings in application code (Perl,
PHP, Java, ASP, etc.).

But I can't find any mention in the MySQL 5.0 stored procedure language
documentation of this capability in stored procedures. I am not aware
that the ANSI/ISO SQL3 "Persistent Stored Modules" standard includes this
functionality, and that is the model on which MySQL based their stored
procedure language.

So no, AFAICT this is not supported in MySQL. It's an extension to the
SQL standard, implemented in a proprietary way by Microsoft and perhaps
some other vendors.

Regards,
Bill K.

Jul 23 '05 #4
Michael C# wrote:
I'm actually trying to do a "Cross-tab" type query.


This is a new kind of problem to me, but after a few Google searches I
found several refereces to an example of generating cross-tabulation
queries in MySQL, by Giuseppe Maxia:

http://www.onlamp.com/pub/a/onlamp/2...crosstabs.html

But if you need to do a dynamic cross-tab query, i.e. querying over an
arbitrary and unknown set of columns and tables, then I think you're out
of luck if you must do it in a stored procedure. There doesn't seem to
be any mechanism for fully dynamic server-side queries in MySQL. You
must do this kind of query in application code, where you can build a
string as a query statement, and then execute the finished query.

If you instead only need a finite number of static cross-tab queries,
you could write one stored procedure for each such query.

Regards,
Bill K.
Jul 23 '05 #5
Thanks again Bill. I googled the heck out of it, and I ended up with a
*lot* of articles on generating cross-tab queries in MS SQL (there are a
surprising number of examples that declare a VarChar variable named
"MySQL" -- go figure). I'm stuck in a situation where the number of columns
and rows is unknown, and varies from query to query... I was trying to
avoid generating the queries in presentation-layer code, but it looks like
that's what I'm going to be stuck with for now...

Thanks
Michael C
"Bill Karwin" <bi**@karwin.com> wrote in message
news:ct*********@enews3.newsguy.com...
Michael C# wrote:
I'm actually trying to do a "Cross-tab" type query.


This is a new kind of problem to me, but after a few Google searches I
found several refereces to an example of generating cross-tabulation
queries in MySQL, by Giuseppe Maxia:

http://www.onlamp.com/pub/a/onlamp/2...crosstabs.html

But if you need to do a dynamic cross-tab query, i.e. querying over an
arbitrary and unknown set of columns and tables, then I think you're out
of luck if you must do it in a stored procedure. There doesn't seem to be
any mechanism for fully dynamic server-side queries in MySQL. You must do
this kind of query in application code, where you can build a string as a
query statement, and then execute the finished query.

If you instead only need a finite number of static cross-tab queries, you
could write one stored procedure for each such query.

Regards,
Bill K.

Jul 23 '05 #6
and the answer is:
Make up a SPT codebase that works in Visual FoxPro , and slam it out to the
mySql database.

I dynamically generate SPT code all the time in my applications ...
I don't recommend you try this with VB - its such a sluff off with munging
data ..
for more info - see http://fox.wikis.com/wc.dll?Wiki~VFPmySQLLinuxP1~VFP
and http://groups.yahoo.com/group/vfpmysql

Going forward- you can have a server side component built in VFP that does
nothing but hold, store and execute SQL queries back at the mysql database,
and the component can be callable in WebServices, SOAP, IIS, ASP, and
ASP.NET [ug]

mondo regards [Bill]

--
William Sanders / Electronic Filing Group Remove the DOT BOB to reply via
email.
Mondo Cool TeleCom -> http://www.efgroup.net/efgcog.html
Mondo Cool WebHosting -> http://www.efgroup.net/efglunar.html
Mondo Cool Satellites -> http://www.efgroup.net/sat
VFP Webhosting? You BET! -> http://efgroup.net/vfpwebhosting
mySql / VFP / MS-SQL

"Michael C#" <xy*@abcdef.com> wrote in message
news:1B****************@fe08.lga...
Thanks Bill. Yeah, it all has to be done server-side in this case.

I was trying to convert some MS SQL code over to MySQL - specifically, some dynamic SQL code that generates "pivot-table" type queries. Anyone have any ideas on how that might be possible?

Thanks,
Michael C

"Bill Karwin" <bi**@karwin.com> wrote in message
news:ct*********@enews4.newsguy.com...
Michael C# wrote:
Is it possible to create Dynamic SQL queries in MySQL, like in SQL
Server? i.e., the EXECUTE command or sp_executesql stored procedure in
SQL Server.


Do you mean in general, or specifically in the MySQL stored procedure
language?

I regularly build SQL statements as strings in application code (Perl,
PHP, Java, ASP, etc.).

But I can't find any mention in the MySQL 5.0 stored procedure language
documentation of this capability in stored procedures. I am not aware
that the ANSI/ISO SQL3 "Persistent Stored Modules" standard includes this functionality, and that is the model on which MySQL based their stored
procedure language.

So no, AFAICT this is not supported in MySQL. It's an extension to the
SQL standard, implemented in a proprietary way by Microsoft and perhaps
some other vendors.

Regards,
Bill K.


Jul 23 '05 #7
Thanks Bill. I'll definitely take a look, but server-side FoxPro isn't an
option with my ISP. I'll get back to you whether it works or not.

Thanks again,
Michael C

"swdev2" <ga*********@efgroup.bob.net> wrote in message
news:gc*******************@newssvr11.news.prodigy. com...
and the answer is:
Make up a SPT codebase that works in Visual FoxPro , and slam it out to
the
mySql database.

I dynamically generate SPT code all the time in my applications ...
I don't recommend you try this with VB - its such a sluff off with munging
data ..
for more info - see http://fox.wikis.com/wc.dll?Wiki~VFPmySQLLinuxP1~VFP
and http://groups.yahoo.com/group/vfpmysql

Going forward- you can have a server side component built in VFP that does
nothing but hold, store and execute SQL queries back at the mysql
database,
and the component can be callable in WebServices, SOAP, IIS, ASP, and
ASP.NET [ug]

mondo regards [Bill]

--
William Sanders / Electronic Filing Group Remove the DOT BOB to reply via
email.
Mondo Cool TeleCom -> http://www.efgroup.net/efgcog.html
Mondo Cool WebHosting -> http://www.efgroup.net/efglunar.html
Mondo Cool Satellites -> http://www.efgroup.net/sat
VFP Webhosting? You BET! -> http://efgroup.net/vfpwebhosting
mySql / VFP / MS-SQL

"Michael C#" <xy*@abcdef.com> wrote in message
news:1B****************@fe08.lga...
Thanks Bill. Yeah, it all has to be done server-side in this case.

I was trying to convert some MS SQL code over to MySQL - specifically,

some
dynamic SQL code that generates "pivot-table" type queries. Anyone have

any
ideas on how that might be possible?

Thanks,
Michael C

"Bill Karwin" <bi**@karwin.com> wrote in message
news:ct*********@enews4.newsguy.com...
> Michael C# wrote:
>> Is it possible to create Dynamic SQL queries in MySQL, like in SQL
>> Server? i.e., the EXECUTE command or sp_executesql stored procedure in
>> SQL Server.
>
> Do you mean in general, or specifically in the MySQL stored procedure
> language?
>
> I regularly build SQL statements as strings in application code (Perl,
> PHP, Java, ASP, etc.).
>
> But I can't find any mention in the MySQL 5.0 stored procedure language
> documentation of this capability in stored procedures. I am not aware
> that the ANSI/ISO SQL3 "Persistent Stored Modules" standard includes this > functionality, and that is the model on which MySQL based their stored
> procedure language.
>
> So no, AFAICT this is not supported in MySQL. It's an extension to the
> SQL standard, implemented in a proprietary way by Microsoft and perhaps
> some other vendors.
>
> Regards,
> Bill K.



Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: George Adams | last post by:
I like the idea of compiling DSO modules for Apache. It allows me to turn on or off things we may or may not need at a given time (like mod_ssl, mod_auth_mysql, mod_auth_ldap, etc.) and also...
74
by: John Wells | last post by:
Yes, I know you've seen the above subject before, so please be gentle with the flamethrowers. I'm preparing to enter a discussion with management at my company regarding going forward as either...
3
by: Angelos | last post by:
Hello again, I have this dynamic menu and I want to change the order of the menu items... I added a column in the database wich has an integer value for ordering the menuitems. But the only way...
2
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
1
by: edfialk | last post by:
Hi all, I'm desperately trying to get a simple mysql connection working in php 4.3.9 and I think I have a doozy for you guys. First of all, I didn't set up ANY of this system, I'm just working...
6
by: traineeirishprogrammer | last post by:
I am currently working on a project where I need to sort my MYSQL query results by different categories. How ever the code does not seem to be working properly and I spend too much time on it...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
8
by: remya1000 | last post by:
i'm using VB \ ASP.NET. i'm trying to display some values in Gridview. but i don't know how many columns i need to display. at run time only i will come to know how many columns i need to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.