By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,117 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,117 IT Pros & Developers. It's quick & easy.

taking count from 3 table

P: 1
I have three tables, history table, office table and invoice .
I Want to total count of each office who has sent the invoice based on the criteria that matches.

This is my query please help me.

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT TOP (100) PERCENT dbo.tbl_jobHistory.RCN, dbo.tbl_invoice.Date, dbo.tbl_office.officeName
  2. FROM         dbo.tbl_jobHistory INNER JOIN
  3.               dbo.tbl_office ON    dbo.tbl_jobHistory.officeID = dbo.tbl_office.officeID LEFT OUTER JOIN
  4.                       dbo.tbl_invoice ON dbo.tbl_jobHistory.invoiceID = dbo.tbl_invoice.invoiceID
  5. WHERE     (dbo.tbl_jobHistory.actionType = 'RDP') AND (NOT (dbo.tbl_invoice.state = 'CA')) AND (dbo.tbl_chits.effectiveDate BETWEEN CONVERT(DATETIME, 
  6.                       '2011-01-01 00:00:00', 102) AND CONVERT(DATETIME, '2011-12-31 00:00:00', 102)) AND (dbo.tbl_office.officeName = dbo.tbl_office.officeName)
  7. ORDER BY dbo.tbl_office.officeName
Mar 20 '12 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 10K+
P: 12,364
Please use code tags when posting code.

A few things.
  • Why are you using distinct?
  • Why are you using top if you're going to return everything anyways?
  • Your last where condition doesn't do anything.
  • If you want to do a count, why don't I see the count function anywhere?
  • Sample data and results are needed because your description is too vague.
Mar 20 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.