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.
| Author |
Topic |
|
steve_c
Yak Posting Veteran
54 Posts |
Posted - 2008-02-27 : 07:35:26
|
| Hi all - having a prob trying to figure this one out! It's an accounts aplication and I need to produce a monthly statement for clients which will be mailed automatically at the end of the month...I have 3 tables (simplified below):Invoiceinvoiceid intinvoicedate datetimeclientid intsubtotal decimal(19,2)paid intCreditcreditid intcreditdate datetimeclientid intsubtotal decimal(19,2)paid intPaymentspaymentid intpaymentdate datetimeamount decimal(19,2)allocated intThe report I need to generate has the client's details at the top and then a list of unpaid invoices, credits and unallocated payments - all sorted by date - with the following columns (sample data supplied)TYPE|DATE|OUR REF|CREDIT|DEBITInvoice | 01-mar-2008 | Inv01 | | £100.00Credit | 02-mar-2008 | Cre23 | £50 |Payment | 03-mar-2008 | P04 | £40 |Would be really grateful for any help!Thanks in advance,Stephen. |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2008-02-27 : 09:22:01
|
| try this Select 'Invoice',..columns from Invoiceunion allSelect 'Credit',..columns from Creditunion allSelect 'Payment',..columns from Payments |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-27 : 12:01:48
|
| [code]SELECT t.Type, t.Date, .............FROM(Select 'Invoice' AS Type,invoicedate as Date,..columns from Invoiceunion allSelect 'Credit' AS Type,creditdate as Date..columns from Creditunion allSelect 'Payment' AS Type,paymentdate as Date,..columns from Payments)tORDER BY t.Date[/code] |
 |
|
|
steve_c
Yak Posting Veteran
54 Posts |
Posted - 2008-02-27 : 14:19:29
|
| Thanks a lot guys - UNION ALL did the job perfectly!Stephen. |
 |
|
|
|
|
|
|
|