如何从表格的选择中排除列中的值 [英] How do I exclude values in a Column in select from a table

查看:183
本文介绍了如何从表格的选择中排除列中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,
表格中的值是

Dear Sir,
The values in a table are

P124,P125,9871780998,P126,BPPQ,P127,PBNN ;


查询是:


A query is:

select top 1 PatCode
from Patient_Detail
where PatCode  like 'P%'
order by PatID desc



目的是选择P127,但它是PBNN.它生成错误[原因P + 127(数字)],因此请修改查询以排除PBNN,结果为P127.



Purpose is to select P127, but it is PBNN. It generate error [reason P+127(numeric)], so please modify the query to exclude PBNN and result is P127.

推荐答案

如何:

How about:

SELECT top 1 PatCode 
FROM Patient_Detail 
WHERE PatCode LIKE 'P%'
AND ISNUMERIC(SUBSTRING(PatCode, 2,LEN(PatCode)-1))=1
ORDER BY PatID DESC



?



?


这篇关于如何从表格的选择中排除列中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆