首页 > 解决方案 > 在 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 行作为输出。上面的查询有什么问题吗?我怎样才能得到想要的结果?

标签: sqlsql-server

解决方案


如果客户编号是整数,为什么不使用:

where customer_no >=  11010000 and
      customer_no <  11020000
      

推荐阅读