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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case Statement Issue

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 PRO


What 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 use

select pro_county + ' County' FROM PRO
Go to Top of Page

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 use

select pro_county + ' County' FROM PRO

Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-24 : 10:26:05
where pro_county not like '% county'

...?

Em
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-07-24 : 10:27:21
you can use replace:

select replace(pro_county,' County','') + ' County'
from Pro

or something along those lines.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

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 use

select pro_county + ' County' FROM PRO




SELECT CASE WHEN PATINDEX('%County%',pro_county)>0 THEN pro_county ELSE pro_county + ' County' END FROM PRO
Go to Top of Page

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 query

select Distinct
case when pro_county<>''then pro_county +'country'
else pro_county end from pro
Go to Top of Page

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 query

select Distinct
case when pro_county<>''then pro_county +'country'
else pro_county end from pro
Go to Top of Page
   

- Advertisement -