操作数类型冲突: varbinary 与 float 不兼容

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:02   2210   0

部署项目测试环境,插入数据时报错!!!

由于本地开发时连接的是 mysql 数据库,但测试服务器的数据库是 sqlserver。

当 insert into qc_earphone(fd_id,fd_low_price……) values(……),如果插入值有 null 值并且 qc_earphone 表中字段类型是 float,则报 操作数类型冲突: varbinary 与 float 不兼容。



解决方案: 不要在 float 类型的字段插入 null 就好了。(但这个在 MySQL 数据库没有影响。)


SQL Server 没有 double 类型

值得注意的是  mysql 有 double 类型,但是 sqlServer 没有。
  • 若是你需要用双精度数据,如果不固定小数位,用 float 就可以了;
  • 若是固定小数位,可以用 numric ;如果整数和小数都出现,可以用 real 。


该列没有包含在聚合函数或 GROUP BY 子句中

同样的在 MySQL 没有出现的情况,连接 sqlserver 就报错。



报错代码:
@Override
 public List<ChenyeeQcCustOrder> getCustOrderInfoWithProductId(String productId) {
  //StringBuilder builder = new StringBuilder();
  String sql = "select * from chenyee_qc_cust_order  where fd_product_id = '" + productId+ "'  and fd_customer_name != null group by fd_customer_name, fd_id";
  //builder.append("from chenyee_qc_cust_order group by fdCustomerName");
  
  Query query = getHibernateSession().createSQLQuery(sql);
  return  query.list();
 }

解决方案:

(必须改成这样才能查询到 SQL server 数据库数据!!!)

@Override
 public List<ChenyeeQcCustOrder> getCustOrderInfoWithProductId(String productId) {
  //StringBuilder builder = new StringBuilder();
  String hql = "select ords.fdCustomerName, ords.fdId,ords.fdProjectName,"
    + "ords.fdRomRam,ords.fdProductPrice,ords.fdBottomPrice,ords.fdPercent,ords.fdUpdateTime,"
    + "ords.fdProduct.fdId,ords.docCreator.fdId from ChenyeeQcCustOrder ords where ords.fdProduct.fdId='" + productId
    + "'  and ords.fdCustomerName!=null group by ords.fdCustomerName, ords.fdId,ords.fdProjectName,"
    + "ords.fdRomRam,ords.fdProductPrice,ords.fdBottomPrice,ords.fdPercent,ords.fdUpdateTime,"
    + "ords.fdProduct.fdId,ords.docCreator.fdId";
  //builder.append("from chenyee_qc_cust_order group by fdCustomerName");
  
  Query query = getHibernateSession().createQuery(hql);
  return  query.list();
 }

看官可以看看这俩者的区别,简单来说,在 sqlserver 中你要查的数据 必须包含在 group by 子句中。

或者用聚合函数形如:

select a,b from tab group by a;
#改成  
select a,count(b) from tab group by a;

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP