MySQL Forums
Forum List  »  German

IF/CASE in SELECT ... WHERE
Posted by: Heiko Wöhrle
Date: January 09, 2013 02:46AM

Hallo,
habe eine vermutlich ganz einfache Anfängerfrage: Ich möchte in einer SELECT ... WHERE-Abfrage mit IF oder CASE arbeiten, bekomme aber die richtige Syntax nicht auf die Reihe.

Ich habe drei Hilfsvariablen, in deren Abhängigkeit die Suche efolgen soll:

VEREINFACHT:
SELECT Daten_A, Daten_B, Daten_C, Hilfs_A, Hilfs_B, Hilfs_C
WHERE
IF(Hilfs_A=0,Daten_A=*,Daten_A=Hilfs_A) AND
IF(Hilfs_B=0,Daten_B=*,Daten_B=Hilfs_B) AND
IF(Hilfs_C=0,Daten_C=*,Daten_C=Hilfs_C)

KONKRETE ABFRAGE:
SELECT `Baustoffe`.`BaustoffID` AS `HauptBS_ID`, `Baustoffe`.`Baustoffart-ID`, `Baustoffe`.`Stammprojekt`, `Hilfs_System`.`Auswahl1`, `Hilfs_System`.`Auswahl2`, `Hilfs_System`.`AuswahlT1` FROM `baustoffe`.`bs-prj-link` AS `BS-PRJ-Link`, `baustoffe`.`baustoffe` AS `Baustoffe`, `baustoffe`.`hilfs_system` AS `Hilfs_System`, `baustoffe`.`oekobaudat` AS `Oekobaudat`WHERE IF( `Hilfs_System`.`Auswahl1`= 0,`Baustoffe`.`Baustoffart-ID` = 300,`Baustoffe`.`Baustoffart-ID` = `Hilfs_System`.`Auswahl1`)

-> Syntax error in SQL expression, SQL-Status HY000, Fehler-Code:1000

MySQL-Version 5.5.18
LibreOffice mit JDBC-Connector

Vielen Dank für eine Antwort im Vorraus,
Heiko

Options: ReplyQuote


Subject
Views
Written By
Posted
IF/CASE in SELECT ... WHERE
2495
January 09, 2013 02:46AM
849
January 09, 2013 11:49AM
832
January 10, 2013 02:11AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.