Skip to content
Advertisement

REGEXP_LIKE conversion in SQL Server T-SQL

I have come across this line in an old report that needs converting to SQL Server.

examCodes being the source and learner_code being the pattern. I know that SQL Server doesn’t have REGEXP_LIKE and most places tell you to use PATINDEX.

Here’s me thinking that this would work:

But I get the error:

On MSDN the syntax is specified as,

But learner_code is a field and I can’t specify a pattern?

I did not write this report in the first place so I’m puzzled to what the pattern it’s looking for anyway.

Many thanks

Advertisement

Answer

If pattern is found , PATINDEX returns non zero value and you need to do a comparison in WHERE clause. A WHERE clause must be followed by comparison operation that returns true / false.

May be you are using PATINDEX without doing the comparison and that is why error message shows non boolean expression near WHERE clause.

To search for pattern learner_code with wildcard character

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement