Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Pattern but not when pattern contained within a string 1

Status
Not open for further replies.

waubain

Technical User
Dec 13, 2011
200
US
I am doing pattern searching and extracting just the number following pattern. This has been answered in thread 1751572.

I was searching for 'LDL', but have come across a pattern where both LDL and VLDL are in the pattern and not always in the same order nor is there a Space always proceeding LDL. This may be similar to finding only men but not women in a string. I tried to exclude the 'V' but just got all zeros.

Here is an examples:
Code:
IF OBJECT_ID('TEMPDB..#demo') IS NOT NULL DROP TABLE #demo
CREATE TABLE #demo(SubjectID int, TextResult varchar(50))
INSERT INTO #demo VALUES (1, 'VLDL 10, LDL 90')
					   ,(2, 'LDL 160, VLDL 35')
					   ,(3, 'VLDL=25 LDL=160')
					   ,(4, 'HDL(60) LDL(160) VLDL(30)')

SELECT
	CHARINDEX('[^V]LDL', [TextResult])
FROM #demo

Thank you.

You don't know what you don't know...
 
Try
Code:
patindex('%[^V]LDL%', [TextResult])
which will not find LDL as the first characters, but I do not know how to do that.
Good luck

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Thanks djj. I thought I tried that variation, but using that as a starting position seemed to work.

Code:
SELECT
	CHARINDEX('LDL', [TextResult], PATINDEX('%[^V]LDL%', [TextResult]))
FROM #demo

Thanks again

You don't know what you don't know...
 
Glad I could help. Sometimes you just have to step back to see you already have the answer.

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top