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.
| 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] |
 |
|
|
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 tablePatient Encounter Number, Discharge Date, Procedure Codes, Diagnosis CodesDiabetes has diagnosis codes of 1 through 10Cardiovascular disease has codes of 11-20Renal Failure....21-35Respiratory Failure....34, 45, 65-70Sepsis....99-100Im able to query out all of these patients, but would like a pivot, frequency distribution..etc of these particular "buckets" and counts. Disease CountDiabetes 42Cardiovascular 20Renal Failure 12Resp Failure 9Sepsis 3Thanks again |
 |
|
|
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 extracted3) format of the desired output as an example .. Order TableID ProductID Price1 1 102 1 10Desired OutputProduct TotalPrice1 20 hope this make sense? CheersMIK |
 |
|
|
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) dgroup 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] |
 |
|
|
boehnc
Starting Member
15 Posts |
Posted - 2011-02-15 : 12:31:34
|
| This is great..thanks! |
 |
|
|
|
|
|
|
|