regexp / substring -- Microsoft SQL 2005 ?

Below "regexp_substr" works in Oracle.

What same type of logic works in Microsoft SQL 2005
so it appears like the attached TWO columns ?
------------------------------------------------------
SELECT     WO_OpID
     -- regexp_substr(WO_OpID, '^[^_]+') AS qty
FROM         Time_Scanning
WHERE     (WO_OpID IS NOT NULL)
s006.jpg
finance_teacherAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
To remove all underscores from column WO_OpID...
SELECT     WO_OpID,  REPLACE(WO_OpID, '_', '') as qty
FROM         Time_Scanning
WHERE     (WO_OpID IS NOT NULL) 

Open in new window

btw nice mockup
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Disregard the above, read the requirements wrong.
Copy-paste the below T-SQL into your SSMS, execute to make sure it works correctly, then modify to meet your needs
Declare @str varchar(15) = 'abc_defg'

SELECT 
	CASE WHEN CHARINDEX('_', @str) > 0 THEN LEFT(@str, CHARINDEX('_', @str) - 1) ELSE '' END as left_side, 
	CASE WHEN CHARINDEX('_', @str) > 0 THEN RIGHT(@str, LEN(@str) - CHARINDEX('_', @str)) ELSE '' END as right_side

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
QuinnDexCommented:
SQL 2005 doesnt have regex function as standard but it is possible to add it using CLR and its not hard to do, see the link below for an example

http://justgeeks.blogspot.co.uk/2008/08/adding-regular-expressions-regex-to-sql.html
0
finance_teacherAuthor Commented:
Below works good.

SELECT     WO_OpID,
           CASE WHEN CHARINDEX('_', WO_OpID) > 0 THEN LEFT(WO_OpID, CHARINDEX('_', WO_OpID) - 1) ELSE '' END AS left_side,
           CASE WHEN CHARINDEX('_', WO_OpID)  > 0 THEN RIGHT(WO_OpID, LEN(WO_OpID) - CHARINDEX('_', WO_OpID)) ELSE '' END AS right_side
FROM         Time_Scanning
WHERE     (WO_OpID IS NOT NULL)
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim

btw if you're used to RegEx, QuinnDex's article could be used to create a SQL function that mimics it.  Worth exploring if that's your comfort level.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.