1

I need to select multiple strings from a single string in that match a patindex. I am selecting the first one using the following code:

CASE WHEN comments like '%[0-9][A-Z][0-9].[0-9]%'
  THEN SUBSTRING(comments,PATINDEX('%[0-9][A-Z][0-9].[0-9]%',comments),5)
  END AS 'Code'

The pattern is number, letter, number, '.', number

Each of the strings that I need to select can be in any position in the string.

Here is an example string: 5D3.5,SLV,4F2.5,4DR,12/03

I need to select 5D3.5 and 4F2.5 from this string. These will all be random and different and need to use the patindex. There are not always commas separating.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
Todd Ensworth
  • 11
  • 1
  • 2

1 Answers1

0

Your (2) Problems : You have a string with a series of values delimited by comma. Then you want to select only some of those values based on specific criteria.

Parsing: You need to first parse the entire string and extract such values. Study this solution How to split a comma-separated value to columns

Selecting: After you solve problem one, this will be a simple select using LIKE.

Community
  • 1
  • 1
Ricardo C
  • 2,205
  • 20
  • 24