Mysql-Fall mit Oder Bedingung

Wie schreibt man einen Fall in der mysql-Abfrage, die prüft, für null oder 0 für eine bestimmte Spalte

 
CREATE TABLE tblConfirmationStatus (Confirm_Status TINY INT) 

INSERT INTO tblConfirmationStatus 
Confirm_Status 
WERTE 
(1), 
(0), 
(1), 
({null}), 
(0), 
(1), 
({null}) 

Erforderliche Leistung

ConfirmStatus

 Bestätigt 
Nicht Bestätigt 
Bestätigt 
Nicht Bestätigt 
Nicht Bestätigt 
Bestätigt 
Nicht Bestätigt 

0 oder "Null" - Nicht Bestätigt, 1-Bestätigt

SELECT CASE Confirm_Status 
WENN NULL ODER 0 DANN "Nicht Bestätigt" 
ELSE 'Bestätigt' ENDE ALS ConfirmStatus 
VON tblConfirmationStatus; 
  • Null-Werte sind hoch ansteckend, und verwandeln Sie jede normale boolean - /Vergleichs-operation in mehr Null-Werte. Eine case-Anweisung ist einfach eine nette Art zu schreiben if (confirm_status = null) .... Sie müssen ISNULL() richtig umzugehen.
InformationsquelleAutor user1187 | 2012-07-30
Schreibe einen Kommentar