Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
toddhd
Yak Posting Veteran
55 Posts |
Posted - 2008-07-14 : 10:42:59
|
| I'm still kinda SQL stupid sometimes, so sorry if this is a dumb question. I want to pull some employee data (name, city, state, phone, etc) using a SELECT statement, -however- if the the country code (i.e. US, CA) is anything other than 'US', then I want city, state and zip to be blank. How do I word a SELECT statement in order to test the country field, and return a blank value instead of the actual data?-Todd Davis |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-14 : 10:44:48
|
Use CASE keyword. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-14 : 10:45:58
|
SELECT Name,CASE Country WHEN 'US' THEN City ELSE '' END AS City,CASE Country WHEN 'US' THEN State ELSE '' END AS State,CASE Country WHEN 'US' THEN Zip ELSE '' END AS Zip,PhoneFROM Table1 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
toddhd
Yak Posting Veteran
55 Posts |
Posted - 2008-07-14 : 12:35:43
|
quote: Originally posted by Peso SELECT Name,CASE Country WHEN 'US' THEN City ELSE '' END AS City,CASE Country WHEN 'US' THEN State ELSE '' END AS State,CASE Country WHEN 'US' THEN Zip ELSE '' END AS Zip,PhoneFROM Table1 E 12°55'05.25"N 56°04'39.16"
Sweet! Thank you very much for the help!-Todd Davis |
 |
|
|
|
|
|
|
|