SELECT t1.id, STUFF((SELECT ',' + CONVERT(VARCHAR, CASE WHEN ISNUMERIC(REPLACE(t2.hsdj, ',', '')) = 1 THEN CAST(REPLACE(t2.hsdj, ',', '') AS FLOAT) ELSE NULL END) FROM formtable_main_43_dt1 t2 WHERE t1.id = t2.mainid FOR XML PATH ('')), 1, 1, '') AS MergedValues, STUFF((SELECT ',' + CAST(CAST(t1.htwj AS VARBINARY(MAX)) AS VARCHAR(MAX)) FROM formtable_main_43 t1 WHERE t1.id = t2.mainid FOR XML PATH ('')), 1, 1, '') AS ImageValues FROM formtable_main_43 t1 INNER JOIN formtable_main_43_dt1 t2 ON t1.id = t2.mainid GROUP BY t1.id t1.htwj;提示“t1”附近有语法错误
时间: 2023-12-16 10:02:27 浏览: 72
Sql中将datetime转换成字符串的方法(CONVERT)
根据你提供的 SQL 语句,应该是这个部分出现了问题:
```
SELECT t1.id, STUFF((SELECT ',' + CONVERT(VARCHAR, CASE WHEN ISNUMERIC(REPLACE(t2.hsdj, ',', '')) = 1 THEN CAST(REPLACE(t2.hsdj, ',', '') AS FLOAT) ELSE NULL END) FROM formtable_main_43_dt1 t2 WHERE t1.id = t2.mainid FOR XML PATH ('')), 1, 1, '') AS MergedValues, STUFF((SELECT ',' + CAST(CAST(t1.htwj AS VARBINARY(MAX)) AS VARCHAR(MAX)) FROM formtable_main_43 t1 WHERE t1.id = t2.mainid FOR XML PATH ('')), 1, 1, '') AS ImageValues FROM formtable_main_43 t1 INNER JOIN formtable_main_43_dt1 t2 ON t1.id = t2.mainid GROUP BY t1.id t1.htwj;
```
在 GROUP BY 子句中,应该使用逗号将分组的列分隔开,而不是空格。所以你需要将 `GROUP BY t1.id t1.htwj` 改为 `GROUP BY t1.id, t1.htwj`。
阅读全文