Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 compute sum()

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2014-08-18 : 05:45:53
I am write a query in below and use the compute sum to calcuate the total qty and amount.

But I don't know how to edit this query to show this text "Total" in beside of amount. Now the result is no "Total" this word.

I try to edit compute "Total", sum(xsopayment.paymentamt) then appear the error message.

-------------------------------------
select xsoheader.voidflag,xsodetail.shopcode,xsodetail.memono,xsodetail.txdate,
xsodetail.sku,xsoheader.depositamt,xsopayment.paymentcode,xsopayment.paymentamt,
xsodetail.itemamt,xsodetail.salesqty

from xsoheader
inner join xsodetail on xsoheader.shopcode + xsoheader.memono = xsodetail.shopcode + xsodetail.memono
inner join xsopayment on xsoheader.shopcode + xsoheader.memono = xsopayment.shopcode + xsopayment.memono
where (xsodetail.sku = 'L000254' or xsodetail.sku='L000256') and xsoheader.voidflag='N' and xsodetail.txdate= CONVERT(varchar(100), GETDATE(), 112)
compute sum(xsopayment.paymentamt) , sum(xsodetail.salesqty)

sz1
Aged Yak Warrior

555 Posts

Posted - 2014-08-18 : 06:58:56
select xsoheader.voidflag,xsodetail.shopcode,xsodetail.memono,xsodetail.txdate,
xsodetail.sku,xsoheader.depositamt,xsopayment.paymentcode,xsopayment.paymentamt,
xsodetail.itemamt,xsodetail.salesqty,
sum(xsopayment.paymentamt) 'Total Payment', sum(xsodetail.salesqty) 'Total QTY',
sum(xsopayment.paymentamt*xsodetail.salesqty) 'Total'

from xsoheader
inner join xsodetail on xsoheader.shopcode + xsoheader.memono = xsodetail.shopcode + xsodetail.memono
inner join xsopayment on xsoheader.shopcode + xsoheader.memono = xsopayment.shopcode + xsopayment.memono
where (xsodetail.sku = 'L000254' or xsodetail.sku='L000256') and xsoheader.voidflag='N'
and xsodetail.txdate= CONVERT(varchar(100), GETDATE(), 112)


We are the creators of our own reality!
Go to Top of Page
   

- Advertisement -