| Author |
Topic |
|
NijelJ22
Starting Member
18 Posts |
Posted - 2008-08-22 : 06:35:29
|
| I have three tables Vendor, Invoice, PaymentVendor contains vendorname and vendottype, vendoridinvoice contains invoiceid, vendoridpayment contains paymentid, vendoridI need the following o/p Vendor Name, Vendor Type , Invoices Uploaded, payments uploadedHint - No of Invoices = count of invoices uploadedNo of payment date = count of payments uploadedI wrote the following query however i m not getting the correct number of records as o/pselect v.VendorName,v.VendorType,count(invoiceid) as Invoices_uploaded,count(paymentdate) as Payments_UpdatedFROM Vendor v JOIN invoice inv on v.VendorID= inv.VendorIDJOIN payment pt on pt.vendorid = v.vendoridGROUP BY v.VendorName,v.VendorTypePlease let me know where i m doing wrong |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-22 : 07:25:07
|
| You need to show us some sample data and explain how tables are related for giving an accurate soln. |
 |
|
|
ma.voice
Starting Member
12 Posts |
Posted - 2008-08-22 : 19:14:50
|
| Hi,You query is looking for multiple related answers. You can either use inline view OR Common table expression. For exampleselect v.VendorName,v.VendorType,count_invoice as Invoices_uploaded,count_paymentdate as Payments_UpdatedFROM Vendor v JOIN (select vendorid,count(1) as count_invoice from invoice group by vendorid) AS inv on v.VendorID= inv.VendorIDJOIN (select vendorid,count(1) as count_paymentdate from payment group by vendorid) AS pt on pt.vendorid = v.vendoridYou can implement similar logic with CTE.cheersSilent VoiceBill Gates, MVP |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-23 : 01:13:13
|
| One reason could be because your Payment contains more than 1 record existing for same invoice. |
 |
|
|
NijelJ22
Starting Member
18 Posts |
Posted - 2008-08-23 : 01:46:50
|
| Thanks Vikash and ma.voice that solves my problem. Regards |
 |
|
|
NijelJ22
Starting Member
18 Posts |
Posted - 2008-08-25 : 06:58:06
|
| Hi...I want to pull records for a specific date range ... Please let me know how can i use where clause with this query ..select v.VendorName,v.VendorType,count_invoice as Invoices_uploaded,count_paymentdate as Payments_UpdatedFROM Vendor v JOIN (select vendorid,count(1) as count_invoice from invoice group by vendorid) AS inv on v.VendorID= inv.VendorIDJOIN (select vendorid,count(1) as count_paymentdate from payment group by vendorid) AS pt on pt.vendorid = v.vendoridWhen i am trying where pt.paymentdate >= '01-8-2008' and pt.paymentdate < '20-8-2008'i am getting an error paymentdate .. Invalid column. However paymentdate exists under payment table.Regards |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-25 : 07:20:56
|
the error is because you're not including it in derived table.try like below and see if it gives you desired result?select v.VendorName,v.VendorType,count_invoice as Invoices_uploaded,count_paymentdate as Payments_UpdatedFROM Vendor v JOIN (select vendorid,count(1) as count_invoice from invoice group by vendorid) AS inv on v.VendorID= inv.VendorIDJOIN (select vendorid,count(1) as count_paymentdate from payment where pt.paymentdate >= '01-8-2008' and pt.paymentdate < '20-8-2008'group by vendorid) AS pt on pt.vendorid = v.vendorid |
 |
|
|
NijelJ22
Starting Member
18 Posts |
Posted - 2008-08-25 : 08:50:25
|
| Thanks a lot.Regards, |
 |
|
|
NijelJ22
Starting Member
18 Posts |
Posted - 2008-09-01 : 05:53:47
|
| i have to add another field in this query. Field name is service name. Now but Service name exists in Service table which only contains two fields Serviceid & ServiceName. No way to link it fron vendor or paymnet table. However, there is another table that contains vendor id and serviceid. Name of table is serviceinvoice. Please help me in modifyng the same query. |
 |
|
|
|