[英]SQL Where clause and like query with letter and numbers
I have a table with project numbers.我有一张包含项目编号的表格。 The project numbers have different formats.
项目编号有不同的格式。 I want to filter just the project numbers starting with
C
and 4 numbers (ie C1234
) and with underscore 3 numbers (ie C1234_123
).我只想过滤以
C
和 4 个数字(即C1234
)和下划线 3 个数字(即C1234_123
)开头的项目编号。 Other formats that i don´t want have a lot more numbers, points in between etc.我不想要的其他格式有更多的数字、中间点等。
Can you help me with the WHERE
clause?你能帮我解决
WHERE
子句吗?
WHERE
Projectnumber LIKE 'C____%'
Here I also get the project numbers that have more than 4 numbers after the C
.在这里我还得到了在
C
之后有超过 4 个数字的项目编号。 How to define a filter for this format C1234_123
?如何为这种格式
C1234_123
定义过滤器?
KR Julia韩币 Julia
Here is the answer with a working example ,这是一个工作示例的答案,
SELECT
[ProjectNumber]
FROM
[Stuff]
WHERE
[ProjectNumber] LIKE 'C[0-9][0-9][0-9][0-9]\_[0-9][0-9][0-9]' ESCAPE '\';
Note the use of the ESCAPE
clause to prevent the _
being treated like a wildcard.请注意使用
ESCAPE
子句来防止_
被视为通配符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.