SELECT 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 '采购单价', ( 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哪里错了,怎么修改
时间: 2023-08-20 09:32:02 浏览: 164
你需要将第二个 SELECT 语句修改为查询品牌信息的语句。假设品牌信息存储在字段 'pinpai' 中,你可以将第二个 SELECT 语句修改为如下语句:
```
(SELECT ',' + pinpai FROM formtable_main_43_dt1 t2 WHERE t1.id = t2.mainid FOR XML PATH('')) AS '品牌'
```
另外,这段 SQL 语句中缺少 GROUP BY 子句,如果你需要按某个字段进行分组,可以在语句末尾添加 GROUP BY 子句。例如,如果你需要按 'id' 字段进行分组,可以将语句修改为如下语句:
```
SELECT
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 '采购单价',
(
SELECT ',' + pinpai
FROM formtable_main_43_dt1 t2
WHERE t1.id = t2.mainid
FOR XML PATH('')
) AS '品牌'
FROM formtable_main_43 t1
GROUP BY t1.id
```
阅读全文