I'm sure I've done this type of operation a 1000 times before but for some reason this is not working for me. I'm doing a report to determine if a patient receive medication on a day. So regardless if they get 1 does or 5 doses in a day the value should be 1. Staff also do corrections on the system, that come in as negative values. So I need to sum all of the dose value for each day, if it is a + value then its 1, otherwise its a 0.
All i want to accomplish at this point is to have 1 row for each date as either 1 or 0.
Here is my SQL Query to sum the values:
SELECT DIM_DRUG_NAME_SHORT.Drug_Name_Short AS 'Med_Name_Short' , SUM(Baseline.Doses) as 'DOT' , Day(Baseline.Dispense_Date) as 'd_Date' FROM FACT_AMS_Baseline_Report Baseline INNER JOIN DIM_DRUG_NAME_SHORT ON Baseline.Med_Name_ID = DIM_DRUG_NAME_SHORT.Drug_Name_Long INNER JOIN DIM_Date tDate ON Baseline.Dispense_Date = tDate.Date WHERE Baseline.Encounter = '00000001/01' GROUP BY DIM_DRUG_NAME_SHORT.Drug_Name_Short , Baseline.Dispense_Date , Doses Order By Drug_Name_Short For time being I'm just pulling one encounter out of the data set to test with. This is the output i'm getting. I also included the Day in the select just to show that the same day is coming through twice and they are not getting Summed.
Here is a sample of the output I get:
Med_Name_Short DOT day of month CEFTRIAXONE 1 15 CEFTRIAXONE 1 16 CEFTRIAXONE 4 16 CEFTRIAXONE 1 17 CEFTRIAXONE 1 18 CEFTRIAXONE 1 20 CEFTRIAXONE -3 21 CEFTRIAXONE 1 21 CEFTRIAXONE -1 23 PROPRANOLOL -1 24 PROPRANOLOL 3 24 PROPRANOLOL 1 25 PROPRANOLOL 2 26 PROPRANOLOL 2 27 What I was hoping to see in this was that Day 16 would be a 5, day 21 would be -2 and day 24 would be -2.
Any assistance would be greatly appreciated. Thanks