SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Parsing Question
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rwlopez
Yak Posting Veteran

80 Posts

Posted - 11/20/2006 :  19:07:49  Show Profile  Reply with Quote
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 - 11/20/2006 :  19:31:27  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000