select '' stockInDay,
a.materialCode,
b.materialName,
b.dimension,
dbo.uf_unitName(b.unitCode) unitName,
sum(isNull(a.materialQty,0)-isNull(a.rtnQty,0)) materialQty,
avg(a.buyingPrice) buyingPrice,
sum(a.buyingAmt) buyingAmt,
sum(a.buyingVat) buyingVat,
'' remark,
'' domesticText,
dbo.UF_STORENAME('1071',a.storeCode) storeName,a.isBuyingvat
from orders a,material b
where a.dealerCode='1071'
and a.storeCode='2166'
and a.stockInDay between '20190528' and '20190528'
and a.dealerCode=b.dealerCode
and a.materialCode=b.materialCode
group by rollup((a.materialcode,b.materialname,b.dimension,unitCode,buyingPrice,buyingVat,a.storeCode,isbuyingvat))
이렇게 코드를 짜서 rollup을 통해 총계는 구했는데
총계135.50을 반올림하여 136으로 보이고싶은데 가능한건가요?
총계에만 반올림 하나요?
아니면 일반합계도 같이 반올림하나요?
null값 있는 열만 하고싶습니다
rollup 내에 괄호가 있네요
case 문으로 분기처리하면 될 것 같습니다
CASE WHEN a.materialcode IS NULL THEN ROUND(sum(isNull(a.materialQty,0)-isNull(a.rtnQty,0)), 0) ELSE sum(isNull(a.materialQty,0)-isNull(a.rtnQty,0)) END
1. "열"이 아니라 "행"이겠죠?
2. 롤업에 합계 항목은 빠져야 하지 않나요?
, buyingPrice, buyingVat
3. 총계만 반올림 하려면.
CASE GROUPING(a.materialcode) WHEN 0 THEN SUM(ISNULL(a.materialQty, 0) - ISNULL(a.rtnQty, 0)) ELSE ROUND(SUM(ISNULL(a.materialQty, 0) - ISNULL(a.rtnQty, 0)), 0) END materialQty