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
 General SQL Server Forums
 New to SQL Server Programming
 How would you go about..

Author  Topic 

boehnc
Starting Member

15 Posts

Posted - 2011-02-09 : 10:15:21
very newbile SQL Server user here...

I have a database of patients with diagnosis codes. I'm querying for 5 different conditions based on different codes. I can write the query that will give me all of the patients, but need to specify which condition each patient qualifies for. What would be the best way to attempt this..thank you.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-09 : 10:21:58
you need to tell us how your table looks like with some sample data and the expected result


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

boehnc
Starting Member

15 Posts

Posted - 2011-02-09 : 10:33:23
Great..thanks KH.

Multiple columns but for the purposes of this question:

We have all of our inpatients in one table

Patient Encounter Number, Discharge Date, Procedure Codes, Diagnosis Codes

Diabetes has diagnosis codes of 1 through 10
Cardiovascular disease has codes of 11-20
Renal Failure....21-35
Respiratory Failure....34, 45, 65-70
Sepsis....99-100

Im able to query out all of these patients, but would like a pivot, frequency distribution..etc of these particular "buckets" and counts.

Disease Count
Diabetes 42
Cardiovascular 20
Renal Failure 12
Resp Failure 9
Sepsis 3


Thanks again

Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-09 : 13:41:24
doesn't make sense to me at-least. Once again i would repeat to provide what KH asked ....

1) tables with some sample data
2) tables should be all those through which the desired output can be extracted
3) format of the desired output

as an example ..

Order Table
ID ProductID Price
1 1 10
2 1 10

Desired Output
Product TotalPrice
1 20


hope this make sense?

Cheers
MIK
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-09 : 21:24:14
[code]
select disease, cnt = count(*)
from
(
select disease = case when codes between 1 and 10 then 'Diabetes'
when codes between 11 and 20 then 'Cardiovascular'
when codes between 21 and 35 then 'Renal Failure'
when codes in (34, 45) or codes between 65 and 70 then 'Respiratory Filure'
end
from yourtbl
) d
group by disease
[/code]

if you have a table that relates the Diagnosis Codes to the Disease, you can INNER JOIN to the inpatients table and does not required the to use case when


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

boehnc
Starting Member

15 Posts

Posted - 2011-02-15 : 12:31:34
This is great..thanks!
Go to Top of Page
   

- Advertisement -