SQLTeam.com | Weblogs | Forums

How to use a found wildcard match?


I want to reference a wildcard match and use that reference to populate a field.

For example:
CASE WHEN [Co1] LIKE 'User%' THEN [Col2] = [the respective User% matched earlier]

How can I do that?
I know how to do it in REGEX, where you use parenthesis in the wildcard to reference the match and then you use \1 to use that wildcard match.

But what is the equivalent in SQL?


T-SQL does not support regex. There are some watered-down commands you can use for wild-card matching etc. There is no feature that allows you to use back-references.

There have been attempts to implement regex support using the .Net framework via CLR - for example here. I have not experimented with any such implementation; you may want to review those.

Often times, people find work arounds for many of the common tasks, so it is possible that you can use the features within T-SQL to accomplish the task.

1 Like