[英]Filter table using Regex like functionality
I have an table on SQL Server which has two columns like below.我在 SQL 服务器上有一个表,它有如下两列。
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.如果
OldValue
和NewValue
列都以“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.