briangriffin
Programmer
I'm collecting an hourly census of hospital patients by department; an ETL package is inserting that data into a table:
Dept Census CensusDate CensusTime InsertDateTime
5W 25 7/1/2011 1600 7/1/2011 16:05:05
5E 15 7/1/2011 1600 7/1/2011 16:05:05
6W 20 7/1/2011 1600 7/1/2011 16:05:05
OBS 5 7/1/2011 1600 7/1/2011 16:05:05
However, if the department has no patients a record is not created:
Dept Census CensusDate CensusTime InsertDateTime
5W 25 7/1/2011 2000 7/1/2011 20:05:05
5E 15 7/1/2011 2000 7/1/2011 20:05:05
6W 20 7/1/2011 2000 7/1/2011 20:05:05
After each load, I need to backfill with records for each department that had no patients. In this example I would need to insert:
Dept Census CensusDate CensusTime InsertDateTime
OBS 0 7/1/2011 2000 7/1/2011 20:05:05
CensusDate and CensusTime are varchar, InsertDateTime is smalldatetime.
The examples I've found online are more complex than this one needs to be. I have a script that works using a crossjoin and a couple of variable tables, but it's a little clumsy. Is there a standard, clever way of doing this?
TIA
Dept Census CensusDate CensusTime InsertDateTime
5W 25 7/1/2011 1600 7/1/2011 16:05:05
5E 15 7/1/2011 1600 7/1/2011 16:05:05
6W 20 7/1/2011 1600 7/1/2011 16:05:05
OBS 5 7/1/2011 1600 7/1/2011 16:05:05
However, if the department has no patients a record is not created:
Dept Census CensusDate CensusTime InsertDateTime
5W 25 7/1/2011 2000 7/1/2011 20:05:05
5E 15 7/1/2011 2000 7/1/2011 20:05:05
6W 20 7/1/2011 2000 7/1/2011 20:05:05
After each load, I need to backfill with records for each department that had no patients. In this example I would need to insert:
Dept Census CensusDate CensusTime InsertDateTime
OBS 0 7/1/2011 2000 7/1/2011 20:05:05
CensusDate and CensusTime are varchar, InsertDateTime is smalldatetime.
The examples I've found online are more complex than this one needs to be. I have a script that works using a crossjoin and a couple of variable tables, but it's a little clumsy. Is there a standard, clever way of doing this?
TIA