parsing field in select statement
Posted on 2010-09-19
In SQL Server 2008, I want to run a select statement and parse a text field and user characters up to a colon symbol, which sometimes does not exist.
The following statement works if all records in that field have a colon, but some don't so it throws an error.
Select substring(myfield,1,charindex(':',title)-1) from mytable
I want to to have a single statement, with a When or if statement I guess, that will return the entire field if there is no colon, otherwise use the substring command.