select T.materialCode, b.materialName, b.dimension, dbo.uf_unitName(b.unitCode) unitName, sum(T.materialQty) materialQty, sum(T.buyingAmt) buyingAmt, sum(T.buyingVat) buyingVat, b.domesticText from (select a.dealerCode, a.materialCode , sum(isNull(a.materialQty,0))-sum(isNull(a.rtnQty,0)) materialQty, sum(isNull(a.buyingAmt,0)) buyingAmt, sum(isNull(a.buyingVat,0)) buyingVat from orders a where a.dealerCode='1001' and a.stockInDay between '20200425' and '20200425' and a.storeCode='2100' group by a.dealerCode,a.materialCode) T,material b where T.dealercode=b.dealerCode and T.materialCode=b.materialCode group by rollup((T.materialCode, b.materialname, b.dimension, b.unitcode, b.domesticText)) order by T.materialCode
를 통해
사진에 null을 총계로바꾸고싶은데 어떻게해야하나요?
1. NULL 값 대체 방법을 이미 쿼리 안 다른 곳에서 사용하고 있네요. ISNULL
- 변경전 : b.materialName
- 변경후 : ISNULL(b.materialName, '총계') materialName
2. ISNULL 사용 개선 필요
- 변경전 : SUM(ISNULL(xxx, 0)) -- 모든 값에 IsNull 처리 후에 합산
- 변경후 : ISNULL(SUM(xxx), 0) -- 최종 합산 결과에 대해서만 IsNull 처리