PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > Select Case problem...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Select Case problem...

Réponse
 
LinkBack Outils de la discussion
Vieux 08/07/2006, 14h45   #1
scole954387@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 is appreciated

Thanks,
S. Cole

  Réponse avec citation
Vieux 08/07/2006, 19h57   #2
zac.carey@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Select Case problem...


scole954387@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 is appreciated
>
> Thanks,
> S. Cole


i don't think you can use subselects pre 4.1

  Réponse avec citation
Vieux 08/07/2006, 20h34   #3
S. Cole
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Select Case problem...

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 s someone else trying to figure out the same.

S. Cole

zac.carey@gmail.com wrote:
> scole954387@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 is appreciated
> >
> > Thanks,
> > S. Cole

>
> i don't think you can use subselects pre 4.1


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h41.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10344 seconds with 11 queries