Advertisement

05.23.2008 at 06:54AM PDT, ID: 23427592
[x]
Attachment Details

Count selected values from a select clause

Asked by healthmanagement in SQL Query Syntax, MS SQL Server

Tags: SQL

Hello experts,

Im trying to count the all the values that are either 'DNA', 'CANX', Closed Open from a query. I want to count each value as display them as seperate colunms in the results.

this is the query that i use to retireve just one colunm
SELECT  distinct   tblClients.strClientName, tblWorkTypes.strName,
                      tblStates4Work.strDesc AS strDesc,  COUNT(dbo.tblStates4Work.strDesc) as totalClosed
FROM         tblClients INNER JOIN
                      tblCases ON tblClients.uidClient = tblCases.fkCompany INNER JOIN
                      tblCaseTypes ON tblCases.fkCaseType = tblCaseTypes.uidCaseType INNER JOIN
                      tblFME ON tblCases.uidCase = tblFME.fkCase INNER JOIN
                      tblStates4Work ON tblFME.fkState4Work = tblStates4Work.uidStates4Work INNER JOIN
                      tblWorkTypes ON tblFME.fkWorkType = tblWorkTypes.uidWorkType
WHERE     (tblFME.ccyFee = 0) and  tblStates4Work.strDesc = 'Closed' and  (tblWorkTypes.strName = 'IMA')
GROUP BY tblClients.strClientName, tblWorkTypes.strName, tblStates4Work.strDesc

This retrieves data like this the last colunm is the data i really need
AA1 TPS      IMA      Closed      4
Air Products      IMA      Closed      2
Allianz       IMA      Closed      1
Ascent       IMA      Closed      3
Aspen Re      IMA      Closed      1
Atkins Ltd      IMA      Closed      5

but what i wan is a single query that retrives all values types.
Does anyone know how to do this?Start Free Trial
[+][-]05.23.2008 at 07:16AM PDT, ID: 21632310

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 07:17AM PDT, ID: 21632320

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 07:31AM PDT, ID: 21632454

View this solution now by starting your 7-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: SQL Query Syntax, MS SQL Server
Tags: SQL
Sign Up Now!
Solution Provided By: dqmq
Participating Experts: 4
Solution Grade: A
 
 
[+][-]05.23.2008 at 07:33AM PDT, ID: 21632472

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 08:42AM PDT, ID: 21633146

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628