[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

SQL Count trouble

Asked by tselectro in MS SQL Server, SQL Server 2008

Tags: Microsoft SQL server

Hello, I have 4 tables, Plant, Plant_Type, Object and Object_Type.

Plant table
ID
Name
TypeID (linked to ID in Plant_Type)

Plant_Type table
ID
Name

Object table
ID
Plant_ID (linked to ID in Plant table)
TypeID  (linked to ID in Object_Type table)

Object_Type table
ID
Name

TypeID field in Plant and Object tables are linked to respective xxx_Type tables. I want to count number of object in Object table group on TypeID for a specific plant type. If no object exists for given plant type, the query should return 0 for that object type.

I have a query as shown below. It work, but if I try to add where condition it does not work as wanted (it only list object that have count > 0, I want to list every object)

SQL ex:
SELECT tblObject_Type.ID, tblObject_Type.Type, Count(tblObject.ID) As ObjectCount
FROM (tblObject
LEFT  JOIN tblObject_Type On tblObject.TypeID = tblObject_Type.ID)
LEFT  JOIN tblPlant On tblObject.Plant_ID = tblPlant.ID
--WHERE tblPlant.TypeID=1
GROUP BY tblObject_Type.ID, tblObject_Type.Type

Result ex:
TypeID|Type|Count
2      Motor      2
1      Pump      1
3      Valve      1

If it does not exists any object of type Motor and Pump for object linked to plant with plant type xx, the result should for ex. be so:
TypeID|Type|Count
2      Motor      0
1      Pumpe      0
3      Ventil      1

I hope someone can help me!

[+][-]11/02/09 06:43 AM, ID: 25719730Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 06:59 AM, ID: 25719923Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 07:20 AM, ID: 25720136Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 09:06 AM, ID: 25721214Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/02/09 09:48 AM, ID: 25721643Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 09:51 AM, ID: 25721676Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 01:35 PM, ID: 25724011Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/02/09 05:06 PM, ID: 25725347Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 05:49 PM, ID: 25725517Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 05:50 PM, ID: 25725521Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: MS SQL Server, SQL Server 2008
Tags: Microsoft SQL server
Sign Up Now!
Solution Provided By: acperkins
Participating Experts: 3
Solution Grade: A
 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625