如何在带有数字字段的 SQL 中使用 LIKE 条件? [英] How to use LIKE condition in SQL with numeric field?

查看:29
本文介绍了如何在带有数字字段的 SQL 中使用 LIKE 条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此查询来获取一些特定数据:select * from emp where emp_name LIKE 's%'";

I'm using this query to get some specific data: "select * from emp where emp_name LIKE 's%'";

emp_nam 是字符字段,如何使用与数字字段相同的逻辑条件?类似:

emp_nam is character field, how can I use the same logic condition with numeric field? something like:

"select * from emp where emp_id ????

"select * from emp where emp_id ????

其中 emp_id 是数字字段.

where emp_id is numeric field.

谢谢,

推荐答案

你不能对数字做通配符,但是,如果你真的需要,你可以将数字转换为 varchar 然后执行通配符匹配.

You can't do a wildcard on a number, however, if you really need to, you can convert the number to a varchar and then perform the wildcard match.

例如

SELECT * FROM emp WHERE CONVERT(varchar(20), emp_id) LIKE '1%'

这篇关于如何在带有数字字段的 SQL 中使用 LIKE 条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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