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 2005 Forums
 Transact-SQL (2005)
 A VERY CHALLENGING SUM

Author  Topic 

gemini_shooter
Starting Member

12 Posts

Posted - 2008-11-19 : 21:46:43
Hello Everyone,

Here I am stuck again at a very challenging SUM, here is the sample data:

No., Ledger, Type, Doc No., Amt,
ABE100, 3914, Invoice, 200-SPI000523, 252
ABE100, 3914, Payment, 5486, -246.69
ABE100, 3914, Credit, SPCM000034, -5.31
ABE100, 11773, Payment, 5503, -4894.63
ABE100, 11773, Payment, 5503, 4894.63
ABE100, 13577, Invoice, SPI000392, 504
ABE100, 25455, Credit, SPCM000034, -5.31
ABE100, 25455, Credit, SPCM000034, 5.31
ABE100, 57672, Credit, SPCM000124, -5

Below is the table I want out of above (Remaining amount field is dynamical created):

No., Ledger, Type, Doc No., Amt, Rem. Amt
ABE100, 3914, Credit, SPCM000034, -5.31, 0
ABE100, 11773, Payment, 5503, -4894.63, 0
ABE100, 13577, Invoice, SPI000392, 504, 504
ABE100, 25455, Credit, SPCM000034, -5.31, 0
ABE100, 25455, Credit, SPCM000034, 5.31, 0
ABE100, 57672, Credit, SPCM000124, -5, -5

I would then like to filter on Entry Type = Credit or Invoice and get the result below:

FOR INVOICE:

No., Ledger, Type, Doc No., Amt, Rem. Amt


ABE100, 13577, Invoice, SPI000392, 504, 504

FOR CREDIT:

No., Ledger, Type, Doc No., Amt, Rem. Amt
ABE100, 3914, Credit, SPCM000034, -5.31, 0
ABE100, 25455, Credit, SPCM000034, -5.31, 0
ABE100, 25455, Credit, SPCM000034, 5.31, 0
ABE100, 57672, Credit, SPCM000124, -5, -5

Can anyone please help me ? PLEASE HELP

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-20 : 01:20:46
what's the rule for getting first set of results from atble? you've got only 1 out of 3 records for 3914 whilst you return all for 25455. what detremines which all are to be returned?
Go to Top of Page
   

- Advertisement -