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
精彩评论