简体   繁体   English

使用类似正则表达式的功能过滤表

[英]Filter table using Regex like functionality

I have an table on SQL Server which has two columns like below.我在 SQL 服务器上有一个表,它有如下两列。

OldValue旧值 NewValue新价值
ReqNo: 123456789申请号:123456789 ReqNo: 89898989申请号:89898989
RandomGibberish: , ReqNo:随机乱码: , ReqNo: RandomGibberish: , ReqNo: 12121212随机乱码: , 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.如果OldValueNewValue列都以“ReqNo:”开头,后跟 8 位数字并且与此模式完全匹配,我希望能够过滤表。

This would mean that the first row would be in my output but not the second row.这意味着第一行将在我的 output 但不是第二行。

I know how to do this in python but still new to SQL Server and can't seem to find the right syntax.我知道如何在 python 中执行此操作,但对于 SQL 服务器来说仍然是新手,并且似乎找不到正确的语法。

Please help.请帮忙。

You could use SQL Server's enhanced LIKE operator here:您可以在此处使用 SQL 服务器的增强型LIKE运算符:

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]';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM