473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

taking count from 3 table

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
1 1470
Rabbit
12,516 Expert Mod 8TB
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

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

Similar topics

2
by: tshad | last post by:
Is there a way to read the current Asp.net page where I may have built some statistics and displayed it on the screen in a Datagrid, and take the table (datagrid) and put it into an email and send...
15
by: l3vi | last post by:
I have a new system Im building that stores entries of what people are searching for on my sites. I want to be able to keep records of how many times a keyword was searched for daily, and from...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
3
by: ret4rt | last post by:
Hello. I have a database with movies similar with imdb and i want to find out which directors have directed both thriller and drama movies. The output i want is like this "DIR_NAME,amount of...
2
by: John Thomas Smith | last post by:
Application reads information from a barcode scanner, to track daily FedEx/Ups/Etc receipts at a loading dock One of the reports is a daily summary, using a query to select information between...
5
by: Roger | last post by:
I am doing some mass update on DB2 8.2 FP10 (say 400 to 500 rows on a 5000 row table) with just one commit. So this is taking lot of exclusive row locks as expected. When I run a select on the...
2
by: nish85 | last post by:
Hi I have a table named StudentResult
1
by: RiddleMeThis | last post by:
In Crystal, I've come across the following code but don't really understand it: COUNT ({tableName1.column1},{tableName1.column1}) I'm involved in creating equivalent reports from an old system...
0
by: srinivasng86 | last post by:
hi ,i generated reports using dataset with compact database where i need to give x axis as sample temperature and y axis Emittance values but i am failed to get y axis values i am getting count of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.