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

Author  Topic 

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2009-01-05 : 14:31:34
I have this case statement...the pro_lname has KONYA, JR I needed to split everything out.

to look like this below. Everything looks good except the EXT. There is a space before JR. How can I get rid of that? See my case statement below.

Last Name/ First Name/ Ext./
KONYA CHARLES Jr


case when charindex(',', impact_prod.dbo.pro.pro_lname)>0
then charindex(',',impact_prod.dbo.pro.pro_lname)-1
else LEN(impact_prod.dbo.pro.pro_lname) end))
end,
CASE WHEN charindex(',', impact_prod.dbo.pro.pro_lname)>0
THEN substring(impact_prod.dbo.pro.pro_lname,charindex(',',impact_prod.dbo.pro.pro_lname) + 1,LEN(impact_prod.dbo.pro.pro_lname)) ELSE NULL END AS EXT,

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-05 : 21:19:38
I am not understanding your requirement. What is the use of first Case statement? Can you explain with sample data and expected output?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-06 : 02:46:05
use LTRIM() to remove leading space
Go to Top of Page
   

- Advertisement -