Home > Mobile >  Filter table using Regex like functionality
Filter table using Regex like functionality

Time:01-21

I have an table on SQL Server which has two columns like below.

OldValue NewValue
ReqNo: 123456789 ReqNo: 89898989
RandomGibberish: , ReqNo: RandomGibberish: , ReqNo: 12121212

I want to be able to filter the table if both the columns OldValue and NewValue start with "ReqNo: " followed by an 8 digit number and are an exact match to this pattern.

This would mean that the first row would be in my output but not the second row.

I know how to do this in python but still new to SQL Server and can't seem to find the right syntax.

Please help.

CodePudding user response:

You could use SQL Server's enhanced LIKE operator here:

SELECT *
FROM yourTable
WHERE OldValue LIKE 'ReqNo: [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' AND
      NewValue LIKE 'ReqNo: [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]';
  •  Tags:  
  • Related