troubleshooting Question

Calculate by Field

Avatar of smartin0924
smartin0924 asked on
Microsoft SQL ServerMicrosoft SQL Server 2005
3 Comments1 Solution204 ViewsLast Modified:
Hello,

I am trying to write a query that will show me the number of patients I have on each team.  Here is the query I pulled out of the query builder in sql, but I can not figure out how to get it to sort by team and calculate the number of patients per team.  Any help would be greatly appreciated.

SELECT     TOP (100) PERCENT dbo.VW_PT_BRANCH.TEAM_DESCRIPTION AS Expr1
FROM         dbo.O_DATASET INNER JOIN
                      dbo.PT_BASIC ON dbo.O_DATASET.DATASET_ID = dbo.PT_BASIC.DATASET_ID INNER JOIN
                      dbo.PT_ADMISSION ON dbo.PT_BASIC.PATIENT_ID = dbo.PT_ADMISSION.PATIENT_ID INNER JOIN
                      dbo.VW_PT_BRANCH ON dbo.PT_BASIC.PATIENT_CODE = dbo.VW_PT_BRANCH.PATIENT_CODE
GROUP BY dbo.PT_ADMISSION.ADMIT_DATE, dbo.PT_ADMISSION.TERMINATION_DATE, dbo.O_DATASET.DATASET_NAME,
                      dbo.VW_PT_BRANCH.TEAM_DESCRIPTION
HAVING      (dbo.O_DATASET.DATASET_NAME = 'Hospice Care Team Inc') AND (NOT (dbo.PT_ADMISSION.ADMIT_DATE IS NULL)) AND
                      (dbo.PT_ADMISSION.TERMINATION_DATE IS NULL)

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros