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 |
|
werhardt
Constraint Violating Yak Guru
270 Posts |
Posted - 2008-07-24 : 10:20:23
|
| I am having problems with my Case Statement. What I am trying to do is put the name county after the county same. Example is I have Montgomery, but I want it to say Montgomery County. For some reason it is not doing that for me.SELECT Distinct CASE pro_county WHEN 'pro_county' THEN 'pro_county' + 'County' ELSE 'pro_county' END FROM PROWhat am I doing wrong? Please help.Thanks! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-24 : 10:22:55
|
| why you need case for this? just useselect pro_county + ' County' FROM PRO |
 |
|
|
werhardt
Constraint Violating Yak Guru
270 Posts |
Posted - 2008-07-24 : 10:24:57
|
oh geez, I didn't even think of that. I guess I am not awake this morning. There are some that say county. How would I make it so some don't come out looking like Montgomery County County?quote: Originally posted by visakh16 why you need case for this? just useselect pro_county + ' County' FROM PRO
|
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 10:26:05
|
| where pro_county not like '% county'...?Em |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-07-24 : 10:27:21
|
| you can use replace:select replace(pro_county,' County','') + ' County' from Proor something along those lines.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-24 : 10:30:24
|
quote: Originally posted by werhardt oh geez, I didn't even think of that. I guess I am not awake this morning. There are some that say county. How would I make it so some don't come out looking like Montgomery County County?quote: Originally posted by visakh16 why you need case for this? just useselect pro_county + ' County' FROM PRO
SELECT CASE WHEN PATINDEX('%County%',pro_county)>0 THEN pro_county ELSE pro_county + ' County' END FROM PRO |
 |
|
|
VGuyz
Posting Yak Master
121 Posts |
Posted - 2008-07-24 : 10:30:43
|
| Is 'pro_county' is a column ..if its a column check the following queryselect Distinct case when pro_county<>''then pro_county +'country'else pro_county end from pro |
 |
|
|
VGuyz
Posting Yak Master
121 Posts |
Posted - 2008-07-24 : 10:31:32
|
| Is 'pro_county' is a column ..if its a column check the following queryselect Distinct case when pro_county<>''then pro_county +'country'else pro_county end from pro |
 |
|
|
|
|
|