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 2000 Forums
 SQL Server Development (2000)
 Parsing Question

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.

ID
1002*38
1003*85
1004*62

I would like to return everything before the * in the data.

1002
1003
1003

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
END
FROM [dbo].[IDTable]


It also handles the case of no asterisk.

Mike
Go to Top of Page
   

- Advertisement -