sql - 在 SQL 查询中的模式匹配期间将列值从真实数据类型转换为字符串
问题描述
我在 SQL 数据库中有一个名为“ customer ”的表,它有一个名为“ customer_no ”的列名,数据类型为real。' customer_no ' 列中包含的数据如下:
customer_no
........
........
54213154
11011011
11011012
11011013
11011014
11011215
11011015
11011101
45121478
........
........
我想使用通配符模式匹配检索以 1101 开头的列值。我正在使用 SQL Server Management Studio。我进行了以下 SQL 查询以获得结果:
select * from customer
where CONVERT(VARCHAR(100), customer_no) like '1101%';
但问题是,我得到 0 行作为输出。上面的查询有什么问题吗?我怎样才能得到想要的结果?
解决方案
如果客户编号是整数,为什么不使用:
where customer_no >= 11010000 and
customer_no < 11020000
推荐阅读
- php - 对codeigniter url路由感到困惑
- android - 原因:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: 合并 dex 档案时出错
- python - 使用 python 3.6.3 从 Box.com 下载 excel 文件
- laravel - Laravel 护照未经来自应用程序而非邮递员的身份验证
- c++ - 如何解释#if/#else 位域?(VC++ 菜鸟)
- git - 如何使 git-show 导出文件为 UTF-8
- android - 在 Android Studio 中渲染布局可视化问题
- javascript - 如何将变量从 json-rpc 传递到 python 脚本
- matlab - 重塑单元格:将具有 i 个观测值的 1xj 单元格转换为具有 j 个观测值的 1xi 单元格
- amazon-cloudformation - 由于未定义的资源策略,IAM 嵌套堆栈无法完成