Multiple charindex values

Hello all,

I wonder if there is a neat efficient way to search for two strings using charindex.

In the below example, I want to search for characters around either "1" OR "2", in the below it is searching for "1". Does anyone have any ideas on how to look for both at the same time?

select client, number, tag_value, SUBSTRING(tag_value, charindex('1', tag_value)-4, 6) from dbo.tag_history

Thanks in advance!

You can use patindex:

select client
      ,number
      ,tag_value
      ,substring(tag_value,patindex('%[1,2]%', tag_value)-4, 6)
  from dbo.tag_history
1 Like

Thanks @bitsmed, I had seen this online but couldn't work out how to implement on my own!