SELECT t1.id, t1.[requestId] AS t1_requestId, t1.[gf] AS '供方', t1.[htmc] AS '合同名称', t1.[htbh] AS '合同编号', t1.[sjbh] AS '编号', t1.[qdrq] AS '签订日期', t1.[qsrq] AS '起始日期', t1.[jzrq] AS '截止日期', t1.[zje] AS '总金额', t1.[zds] AS '总吨数', t1.[rksj] AS '入库时间', t1.[chpt] AS '撮合平台', t1.[htwj] AS '合同文件', t1.[qsfs] AS '签署方式', t1.[gfjc] AS '供方简称', t1.[cclx] AS '持仓类型', STUFF( ( SELECT ',' + CONVERT ( VARCHAR, CASE WHEN ISNUMERIC( REPLACE( t2.hsdj, ',', '' ) ) = 1 THEN CAST ( REPLACE( t2.hsdj, ',', '' ) AS FLOAT ) END ) FROM formtable_main_43_dt1 t2 WHERE t1.id = t2.mainid FOR XML PATH ( '' ) ), 1, 1, '' ) AS '采购单价' FROM formtable_main_43 t1 INNER JOIN formtable_main_43_dt1 t2 ON t1.id = t2.mainid GROUP BY t1.id, t1.[requestId], t1.[gf], t1.[htmc], t1.[htbh], t1.[sjbh], t1.[qdrq], t1.[qsrq], t1.[jzrq], t1.[zje], t1.[zds], t1.[rksj], t1.[chpt], t1.[htwj], t1.[qsfs], t1.[gfjc], t1.[cclx], '采购单价';提示不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符,怎么更改才正确
时间: 2024-01-20 18:04:01 浏览: 87
CHTMLDemo.rar
你可以在查询中排除包含 text、ntext 和 image 数据类型的列,或者将它们转换为可比较的数据类型。在这个查询中,你可以尝试将 '采购单价' 列的数据类型转换为可比较的数据类型。可以使用 CAST 或 CONVERT 函数将其转换为浮点数类型。修改后的查询如下所示:
```
SELECT t1.id, t1.[requestId] AS t1_requestId, t1.[gf] AS '供方', t1.[htmc] AS '合同名称', t1.[htbh] AS '合同编号', t1.[sjbh] AS '编号', t1.[qdrq] AS '签订日期', t1.[qsrq] AS '起始日期', t1.[jzrq] AS '截止日期', t1.[zje] AS '总金额', t1.[zds] AS '总吨数', t1.[rksj] AS '入库时间', t1.[chpt] AS '撮合平台', t1.[htwj] AS '合同文件', t1.[qsfs] AS '签署方式', t1.[gfjc] AS '供方简称', t1.[cclx] AS '持仓类型', CAST(STUFF( ( SELECT ',' + CONVERT (VARCHAR, CASE WHEN ISNUMERIC(REPLACE(t2.hsdj, ',', '')) = 1 THEN CAST(REPLACE(t2.hsdj, ',', '') AS FLOAT) END ) FROM formtable_main_43_dt1 t2 WHERE t1.id = t2.mainid FOR XML PATH('') ), 1, 1, '' ) AS FLOAT) AS '采购单价' FROM formtable_main_43 t1 INNER JOIN formtable_main_43_dt1 t2 ON t1.id = t2.mainid GROUP BY t1.id, t1.[requestId], t1.[gf], t1.[htmc], t1.[htbh], t1.[sjbh], t1.[qdrq], t1.[qsrq], t1.[jzrq], t1.[zje], t1.[zds], t1.[rksj], t1.[chpt], t1.[htwj], t1.[qsfs], t1.[gfjc], t1.[cclx], '采购单价';
```
如果这样修改后还是提示错误,那么可能是其他列包含了 text、ntext 和 image 数据类型,你需要进一步检查并进行相应的修改。
阅读全文