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 |
rwlopez
Yak Posting Veteran
80 Posts |
Posted - 2006-11-20 : 19:07:49
|
I am trying to parse a string in a SELECT Statement, but I am not sure of the approach to take. I am trying to do the following.ID1002*381003*851004*62I would like to return everything before the * in the data.100210031003 |
|
Morlin
Starting Member
2 Posts |
Posted - 2006-11-20 : 19:31:27
|
Try this:SELECT ID1 = CASE WHEN (CharIndex('*', ID) > 0) THEN LEFT(ID, (CharIndex('*', ID) - 1)) ELSE ID ENDFROM [dbo].[IDTable]It also handles the case of no asterisk.Mike |
|
|
|
|
|