开发者

In SQL how to I exclude a record if there are more than 3 characters after a dash

开发者 https://www.devze.com 2022-12-26 18:48 出处:网络
In SQL how do I exclude a record if there are more than 2 characters after a dash.. Example I only want to return records that match the following

In SQL how do I exclude a record if there are more than 2 characters after a dash..

Example I only want to return records that match the following AA00000-0

but the table also has recoreds like AA0000-000,AA0000000-00

I need to re开发者_开发知识库turn only records that have a single digit after the dash


As mentioned, digit matching is not consistent across databases.

For SQL Server, you can do:

MyColumn LIKE '%-[0-9]' (will get it with only a digit after the dash)

Database-agnostic:

MyColumn LIKE '%-_' (would match a digit or 1 letter after the dash, but that may be sufficient)


LIKE '%-[0-9]'

Filler Filler Filler Filler


Assuming SQL Server:

SELECT * FROM records WHERE id NOT LIKE '%-[0-9][0-9]%'


Use a like statement.

Field Like '%-[0-9]'


What database are you using?

In MSSQL you could: where fld not like '%-__'


thanks for all the answers, the solution I used was

Like '%-_'

The single underscore represents the first digit after the dash

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号