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_DESC RIPTION 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_I D INNER JOIN
dbo.VW_PT_BRANCH ON dbo.PT_BASIC.PATIENT_CODE = dbo.VW_PT_BRANCH.PATIENT_C ODE
GROUP BY dbo.PT_ADMISSION.ADMIT_DAT E, dbo.PT_ADMISSION.TERMINATI ON_DATE, dbo.O_DATASET.DATASET_NAME ,
dbo.VW_PT_BRANCH.TEAM_DESC RIPTION
HAVING (dbo.O_DATASET.DATASET_NAM E = 'Hospice Care Team Inc') AND (NOT (dbo.PT_ADMISSION.ADMIT_DA TE IS NULL)) AND
(dbo.PT_ADMISSION.TERMINAT ION_DATE IS NULL)
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_DESC
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_I
dbo.VW_PT_BRANCH ON dbo.PT_BASIC.PATIENT_CODE = dbo.VW_PT_BRANCH.PATIENT_C
GROUP BY dbo.PT_ADMISSION.ADMIT_DAT
dbo.VW_PT_BRANCH.TEAM_DESC
HAVING (dbo.O_DATASET.DATASET_NAM
(dbo.PT_ADMISSION.TERMINAT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ps: avoid the query builder as much as possible. it produces quite ugly and usually unefficient code :)
ASKER
You Rock!!!! Thanks for the quick responce.