Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 This works how do I count Pt Numbers?

Author  Topic 

LOgle0917
Starting Member

9 Posts

Posted - 2008-06-27 : 15:48:58
I have tried several different ways and cannot get it to work. I found code for a table with 1 field but how would I do a count here? Please help. For instance I need to see the total number of Patients.

SELECT PAT_NBR,DT_OF_SERVICE,PERF_PHYS_NBR,DISPLAY_NM,DIAG_CD,DIAG_CD_DESC,PROC_CD,PROC_CD_DESC_1

FROM OI_CHARGES, PHYSICIAN,PC_DESC,DIAGNOSIS_CD

WHERE OI_CHARGES.PERF_PHYS_NBR=PHYSICIAN.PHYS_NBR
AND OI_CHARGES.DIAG_CD=DIAGNOSIS_CD.DIAGNOSIS_CD
AND OI_CHARGES.PROC_CD=PC_DESC.PC_PROC_CD
AND
AGC_CD = 'OBGYN' AND DT_OF_SERVICE BETWEEN '20070701' AND '20080630';




Thanks!
Lisa

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-28 : 02:41:30
Without having some sample data from the tables involved,its very difficult to provide an accurate solution. So can you provide the table structures and sample data please? it will something like:-

SELECT COUNT(PAT_NBR) AS PatientCount

FROM OI_CHARGES, PHYSICIAN,PC_DESC,DIAGNOSIS_CD

WHERE OI_CHARGES.PERF_PHYS_NBR=PHYSICIAN.PHYS_NBR
AND OI_CHARGES.DIAG_CD=DIAGNOSIS_CD.DIAGNOSIS_CD
AND OI_CHARGES.PROC_CD=PC_DESC.PC_PROC_CD
AND
AGC_CD = 'OBGYN' AND DT_OF_SERVICE BETWEEN '20070701' AND '20080630';


provided the tables are all 1:1 related this will give you full patient count.

SELECT COUNT(PAT_NBR) AS PatientCount,PERF_PHYS_NBR

FROM OI_CHARGES, PHYSICIAN,PC_DESC,DIAGNOSIS_CD

WHERE OI_CHARGES.PERF_PHYS_NBR=PHYSICIAN.PHYS_NBR
AND OI_CHARGES.DIAG_CD=DIAGNOSIS_CD.DIAGNOSIS_CD
AND OI_CHARGES.PROC_CD=PC_DESC.PC_PROC_CD
AND
AGC_CD = 'OBGYN' AND DT_OF_SERVICE BETWEEN '20070701' AND '20080630'
GROUP BY PERF_PHYS_NBR


and this count of patients per physician. But i cant guarantee this gives you what you want unless i'm sure of how tables are related and how data will be for which you've provide what's asked above.
Go to Top of Page
   

- Advertisement -