Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have table MLD. I want that Invoiceno,sumof InvoicAmt of same orderno,CreatedDate and first invoice which have same createddate and orderno.
OrderNo       InvoiceNo     CreatedDate     InvoiceAmt      Qty
--------------------------------------------------------------------------------------
101           5012         11-Apr-2014      5200.00         31
101           5013         11-Apr-2014      1800.00         12
105           5083         14-Apr-2014      1800.00         12
105           3013         14-Apr-2014      4800.00         17
108           2304         18-Apr-2014      2612.00         41

I want result like this. How it is possible?
OrderNo       InvoiceNo      CreatedDate      InvoiceAmt      Qty
--------------------------------------------------------------------------------------
101            5012          11-Apr-2014       7000.00        43 
105            5083          14-Apr-2014       6600.00        12
108            2304          18-Apr-2014       2612.00        41

Please give me solution ....
Posted
Updated 12-Apr-14 21:05pm
v3

Use "Group by" Clause in your query
 
Share this answer
 
Comments
Amit Vasi 13-Apr-14 1:37am    
but how to get First InvoiceNum and Sum of All Invoices of same order and same date ?
Amit Vasi 13-Apr-14 1:37am    
Please give me query
Try this:
SQL
with cte  (orderno, createddate, invoiceamt, qty)
as
(
select orderno, createddate, sum(invoiceamt), sum(qty)
from mld group by orderno, createddate
) select orderno,
(select top 1 invoiceno from mld where mld.orderno = cte.orderno),
createddate, invoiceamt, qty
from cte
 
Share this answer
 
v2
Comments
Amit Vasi 13-Apr-14 3:04am    
Thanks alot...It has solved my problem...thanks
Peter Leow 13-Apr-14 3:28am    
You are welcome.
This is a simple way...
SQL
select 
     min(OrderNo) OrderNo,
     min(InvoiceNo) InvoiceNo,
     CreatedDate,
     sum(InvoiceAmt) InvoiceAmt,
     sum(Qty) Qty
From
     tblName
Group by 
     CreatedDate

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900