SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 remove duplicate row Group by and rollup
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

usafelix
Yak Posting Veteran

Hong Kong
90 Posts

Posted - 08/22/2014 :  13:03:18  Show Profile  Reply with Quote
Please edit my query how to remove the duplicate row ? attached of result in below
-------------------------------------------
select
isnull(xsodetail.txdate,'') As Date,
case when xsoheader.shopcode is null
then ' Total'
else
'Shop '+xsoheader.shopcode end as shop,
round(sum(isnull(xsopayment.paymentamt,0)),0) as Amount,
sum(isnull(xsoheader.depositamt,0)) as Deposit_Amount,
isnull(xsopayment.paymentcode,'') as Paycode,
isnull(max(xsodetail.sku),'') as COUPON,
sum(isnull(xsodetail.itemamt,0)) as amount,
sum(isnull(xsodetail.salesqty,0)) as Qty

from xsoheader
inner join xsodetail on xsoheader.shopcode + xsoheader.memono = xsodetail.shopcode + xsodetail.memono
inner join xsopayment on xsopayment.shopcode+xsopayment.memono = xsoheader.shopcode+xsoheader.memono
where (xsodetail.sku ='L000254' or xsodetail.sku='L000256') and xsoheader.voidflag='N'
group by xsodetail.txdate,xsoheader.shopcode, xsoheader.depositamt,xsopayment.paymentcode,xsodetail.itemamt,xsodetail.sku,xsodetail.salesqty
with rollup

-----------------------------------------------------------
current result :
Date,shop, deposit amount payment sku pay_amt qty

------------------------------------------------------------
20140805 Shop TS502 $ 5000.00 0.00 EPS L000254 5000.00 1.00
20140805 Shop TS502 $ 5000.00 0.00 EPS L000254 5000.00 1.00
20140805 Shop TS502 $ 5000.00 0.00 EPS L000254 5000.00 1.00
20140805 Shop TS502 $ 5000.00 0.00 EPS L000254 5000.00 1.00
20140805 Shop TS502 $ 5000.00 0.00 L000254 5000.00 1.00
20140805 Shop TS502 $ 5000.00 0.00 L000254 5000.00 1.00
20140805 Total $ 5000.00 0.00 L000254 5000.00 1.00
20140806 Shop MC501 $ 100.00 100.00 MOP L000254 10000.00 2.00
20140806 Shop MC501 $ 100.00 100.00 MOP L000254 10000.00 2.00
20140806 Shop MC501 $ 100.00 100.00 MOP L000254 10000.00 2.00
20140806 Shop MC501 $ 100.00 100.00 MOP L000254 10000.00 2.00
20140806 Shop MC501 $ 100.00 100.00 L000254 10000.00 2.00
20140806 Shop MC501 $ 100.00 100.00 L000254 10000.00 2.00
20140806 Total $ 100.00 100.00 L000254 10000.00 2.00

MichaelJSQL
Posting Yak Master

169 Posts

Posted - 08/22/2014 :  13:33:39  Show Profile  Reply with Quote
It would be easier if you had included table DDL and some row data

Why do you have your aggregates in your Group by?

select
isnull(xsodetail.txdate,'') As Date,
case when xsoheader.shopcode is null
then ' Total'
else
'Shop '+xsoheader.shopcode end as shop,
round(sum(isnull(xsopayment.paymentamt,0)),0) as Amount,
sum(isnull(xsoheader.depositamt,0)) as Deposit_Amount,
isnull(xsopayment.paymentcode,'') as Paycode,
isnull(max(xsodetail.sku),'') as COUPON,
sum(isnull(xsodetail.itemamt,0)) as amount,
sum(isnull(xsodetail.salesqty,0)) as Qty

from xsoheader
inner join xsodetail on xsoheader.shopcode + xsoheader.memono = xsodetail.shopcode + xsodetail.memono
inner join xsopayment on xsopayment.shopcode+xsopayment.memono = xsoheader.shopcode+xsoheader.memono
where (xsodetail.sku ='L000254' or xsodetail.sku='L000256') and xsoheader.voidflag='N'
group by xsodetail.txdate,xsoheader.shopcode
with rollup
Go to Top of Page

usafelix
Yak Posting Veteran

Hong Kong
90 Posts

Posted - 08/22/2014 :  14:27:01  Show Profile  Reply with Quote
Dear Sir,
I am simple request output is sort by shop + date + sku and show the grand total amount and qty in last row to display with no duplicate record. How I can delete the replicate row ?

Thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000