根据sql server中的值消除记录

bmsqldev

我有一个table如下

id    record

1    5000tax
2    tax5000
3    tax5001
4    taxpro
5    val5005

我需要检索以字母开头的记录。我写下面的查询

select id, record, right(record,4) as code
from table
where left(record,1) like 'A' and 'Z'

输出:

id  record   code

2   tax5000  5000
3   tax5001  5001
4   taxpro   xpro
5   val5005  5005

在这里,我不想包含records其中没有任何数字的内容。即xpro。

我写下面的查询

  select id, record, right(record,4) as code
    from table
    where left(record,1) like 'A' and 'Z'
    and record between '0' and '9'

它没有任何输出。

谢谢您的帮助

(PS:在表中禁用了全文搜索属性)

托斯滕·凯特纳(Thorsten Kettner)

你可以用[0-9]LIKE

select id, record, right(record, 4) as code
from table
where record like '[A-Z]%'
  and record like '%[0-9]%';

或者,如果末尾总是四位数字,则:

select id, record, right(record, 4) as code
from table
where record like '[A-Z]%'
  and record like '%[0-9][0-9][0-9][0-9]';

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章