473,386 Members | 1,860 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,386 software developers and data experts.

Select Case problem...

Hi,

I have a problem. I have written a SQL statement that has a nested
select case statement on the 'where' clause to condition the results.

--------------------------------------------------------
SELECT b.ISBN, b.Title, b.SmallImage, f.idForSale, count(f.idForSale)

FROM books b, forsale f

WHERE b.idBooks=f.Books_idBooks AND (select case when %s = 0 then
f.BookCondition_idConditions>0 ELSE f.BookCondition_idConditions=%s
end)

GROUP BY b.ISBN

--------------------------------------------------------

The statement works fine on my test server running Apache2, however
receives the following error on the production server running MySQL
4.0.25-standard-log.

Error:
You have an error in your SQL syntax. Check the manual that corresponds
to your MySQL server version for the right syntax to use near 'select
case when 1 = 0 then f.BookCondition_idConditions>0 ELSE

Same error received no matter what value %s gets (0,1,2, etc).

Anyone have any ideas why the statement doesn't work on my production
server? I've researched the mysql manual and select case appears to be
a valid function for this version of mysql.

Any help is appreciated

Thanks,
S. Cole

Jul 8 '06 #1
2 5155

sc*********@gmail.com wrote:
Hi,

I have a problem. I have written a SQL statement that has a nested
select case statement on the 'where' clause to condition the results.

--------------------------------------------------------
SELECT b.ISBN, b.Title, b.SmallImage, f.idForSale, count(f.idForSale)

FROM books b, forsale f

WHERE b.idBooks=f.Books_idBooks AND (select case when %s = 0 then
f.BookCondition_idConditions>0 ELSE f.BookCondition_idConditions=%s
end)

GROUP BY b.ISBN

--------------------------------------------------------

The statement works fine on my test server running Apache2, however
receives the following error on the production server running MySQL
4.0.25-standard-log.

Error:
You have an error in your SQL syntax. Check the manual that corresponds
to your MySQL server version for the right syntax to use near 'select
case when 1 = 0 then f.BookCondition_idConditions>0 ELSE

Same error received no matter what value %s gets (0,1,2, etc).

Anyone have any ideas why the statement doesn't work on my production
server? I've researched the mysql manual and select case appears to be
a valid function for this version of mysql.

Any help is appreciated

Thanks,
S. Cole
i don't think you can use subselects pre 4.1

Jul 8 '06 #2
Thanks for the reply.

I got it to work by removing the () and the SELECT before the case...
so the sql that worked was:

------------------------------------
SELECT b.ISBN, b.Title, b.SmallImage, f.idForSale, count(f.idForSale)

FROM books b, forsale f

WHERE b.idBooks=f.Books_idBooks AND CASE WHEN %s = 0 THEN
f.BookCondition_idConditions>0 ELSE f.BookCondition_idConditions=%s END

GROUP BY b.ISBN
------------------------------------

Hope this helps someone else trying to figure out the same.

S. Cole

za*******@gmail.com wrote:
sc*********@gmail.com wrote:
Hi,

I have a problem. I have written a SQL statement that has a nested
select case statement on the 'where' clause to condition the results.

--------------------------------------------------------
SELECT b.ISBN, b.Title, b.SmallImage, f.idForSale, count(f.idForSale)

FROM books b, forsale f

WHERE b.idBooks=f.Books_idBooks AND (select case when %s = 0 then
f.BookCondition_idConditions>0 ELSE f.BookCondition_idConditions=%s
end)

GROUP BY b.ISBN

--------------------------------------------------------

The statement works fine on my test server running Apache2, however
receives the following error on the production server running MySQL
4.0.25-standard-log.

Error:
You have an error in your SQL syntax. Check the manual that corresponds
to your MySQL server version for the right syntax to use near 'select
case when 1 = 0 then f.BookCondition_idConditions>0 ELSE

Same error received no matter what value %s gets (0,1,2, etc).

Anyone have any ideas why the statement doesn't work on my production
server? I've researched the mysql manual and select case appears to be
a valid function for this version of mysql.

Any help is appreciated

Thanks,
S. Cole

i don't think you can use subselects pre 4.1
Jul 8 '06 #3

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

Similar topics

17
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to...
0
by: Michael | last post by:
I have a problem forcing files to download. If I select Save the document is saved with no problems. If I select "Open" the document is empty or I get a "File not found" error from the application...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
2
by: JMCN | last post by:
hello i have your basic select case question. i created a combo box and save it as a query. so whenever the user selects the value and clicks the export button, the select case should then export...
10
by: MLH | last post by:
Suppose the following... Dim A as Date A=#7/24/2005# I wish to compare value of A against 2 other values: 1) 8/1/2005 2) 9/1/2005 Which is better and why... First:
3
by: mark.irwin | last post by:
Hello all, Have an issue where a redirect pushes data to a page with a select case which then redirects to another page. Problem is the redirect isnt working in 1 case. Code below: strURL =...
8
by: | last post by:
Hello, This is gonna sound real daft, but how do I test a Select Case statement for variants of a theme? Here's a snippet of my code... Select Case sUsr Case "Guest", "TsInternetUser",...
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.