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
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Derived Column Expression Parsing Text

Author  Topic 

afaa
Starting Member

16 Posts

Posted - 2009-04-01 : 20:10:45
Hello All,
I'm having some trouble coming up with the expression to parse a text column.
Here's my example:
Column Text:
abc-de
fgh*ij
klmno

I want to take everything left of the - or * if those symbols exists, else take the default. So my result should look like this:
abc
fgh
klmno

I'd tried playing with the SUBSTRING, FINDSTRING and conditional operator. The problem is having multiple conditions is making it complex.

All help and comments appreciated.

afaa
Starting Member

16 Posts

Posted - 2009-04-03 : 12:06:49
I figured it out. Here's what I did:
FINDSTRING(Column,"-",1) > 0 ? SUBSTRING(Column,1,FINDSTRING(Column,"-",1) - 1) : FINDSTRING(Column,"*",1) > 0 ? SUBSTRING(Column,1,FINDSTRING(Column,"*",1) - 1): Column

In doing this I realized that the Conditional operator ? is like an if then else statement where before the ? is the if, and after the ? is the then and after the : is the else. Hope that helps someone.
Go to Top of Page
   

- Advertisement -