Click here to Skip to main content
15,896,300 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the customers' table, many customers do not have state data in the state column therefore when we select customers, the state column displays NULL values, which is not meaningful for the reporting purpose.

customerNumber   customerName         state   country
 103           Atelier graphique       NULL    France 
112           Signal Gift Stores        NV      USA


I am trying to improve the output by using the case, but getting an 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 ' THEN 'N/A' ELSE state END) as state, country FROM customers' at line 5"


What I have tried:

<pre>SELECT 
    customerNumber,
    customerName,
    STATE 1= ( CASE State
When NULL Then'N/A'
ELSE state
			 END),
    country
FROM
    customers;
Posted
Updated 23-May-18 22:23pm

 
Share this answer
 
Comments
Maciej Los 24-May-18 4:23am    
5ed!
In addition to Richard MacCutchan[^]'s answer:
SQL
SELECT 
    customerNumber,
    customerName,
    CASE When State IS NULL Then'N/A' ELSE State END AS State,
    country
FROM
    customers;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900