[英]How to get numeric OR starting with letter with numbers in a field (SQL SSMS 2016)
Using SSMS 2016使用 SSMS 2016
I have this field:我有这个领域:
+--------+
| ID |
+--------+
| ASDFG |
| S1234 |
| S4321 |
| 123456 |
| 654321 |
| GFDSA |
+--------+
I want to keep those which are numeric OR starting with S with numbers我想保留那些数字或以 S 开头的数字
Desired output:期望的输出:
+--------+
| ID |
+--------+
| S1234 |
| S4321 |
| 123456 |
| 654321 |
+--------+
I tried something like this but didn't work我试过这样的事情,但没有奏效
where Isnumeric(ID) = 1 and ID Like 'S[0-9]%'
I'm hoping it's something small I'm missing so any assistance most welcome我希望这是我遗漏的小东西,所以欢迎任何帮助
EDIT: Just realised that I should've put down OR in the clause.编辑:刚刚意识到我应该在条款中放下 OR。 D'oh!哦!
where (Isnumeric(ID) = 1 OR ID Like 'S[0-9]%')
NB: IsNumeric
will lie to you .注意: IsNumeric
会骗你。 It would probably be better to combine two Like
statements:结合两个Like
语句可能会更好:
WHERE ID Like 'S[0-9]%'
Or ID Not Like '%[^0-9]%'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.