Avatar of smartin0924
smartin0924 asked on

Calculate by Field

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)

Microsoft SQL Server 2005Microsoft SQL Server

Avatar of undefined
Last Comment
smartin0924

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Guy Hengel [angelIII / a3]

ps: avoid the query builder as much as possible. it produces quite ugly and usually unefficient code :)
ASKER
smartin0924

You Rock!!!!  Thanks for the quick responce.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23