Home Forums SQL Server 2008 T-SQL (SS2K8) T sql for patient arrivals, transfers In and Out and discharges and census on a hospital floor by hour RE: T sql for patient arrivals, transfers In and Out and discharges and census on a hospital floor by hour

  • Since you're new, I'll go easy on you... <g>

    One thing to keep in mind when posting questions is that you're the only one with access to your database, so if you want a real answer, post real structures. (but NOT real data... and enough to explain what's going on... if 3 records will do, no need to add more!)

    Here's a create table and insert statements...

    create table #visit (

    VisitID char(15),

    VCode CHAR(8),

    EffectiveDate DATETIME,

    LocationID char(4),

    OldLocationID char(4)

    );

    -- inserts---

    INSERT INTO #visit VALUES('10001520449','ENADMIN','11/12/13 7:35 AM','LDR',NULL);

    INSERT INTO #visit VALUES('10001520313','ENADMIN','11/5/13 6:03 AM','HOLD',NULL);

    INSERT INTO #visit VALUES('10001520313','TFRADMIN', '11/5/13 12:26 PM','5S','HOLD');

    INSERT INTO #visit VALUES('10001520313', 'ENDISIN', '11/8/13 12:39 PM',NULL,NULL);

    INSERT INTO #visit VALUES('10001519626','ENADMIN','11/12/13 6:13 AM','HOLD',NULL);

    INSERT INTO #visit VALUES('10001519626','TFRADMIN','11/12/13 12:41 PM','5W','HOLD');

    INSERT INTO #visit VALUES('10001505051','ENADMIN','11/8/13 10:29 AM','LDR',NULL);

    INSERT INTO #visit VALUES('10001505051','TFRADMIN','11/8/13 2:27 PM','LDR','DR');

    INSERT INTO #visit VALUES('10001505051','TFRADMIN','11/8/13 3:25 PM','3S','DR');

    INSERT INTO #visit VALUES('10001505051','TFRADMIN','11/10/13 11:11 AM','3S','N3S');

    INSERT INTO #visit VALUES('10001505051','ENDISIN','11/11/13 11:30 AM',NULL,NULL);

    INSERT INTO #visit VALUES('10001502123','ENADMIN','11/5/13 10:44 AM','HOLD',NULL);

    INSERT INTO #visit VALUES('10001502123','TFRADMIN','11/5/13 6:27 PM','5S','HOLD');

    INSERT INTO #visit VALUES('10001502123','ENDISIN','11/7/13 1:19 PM',NULL,NULL);

    INSERT INTO #visit VALUES('10001501299','ENADMIN','11/5/13 9:04 AM','HOLD',NULL);

    INSERT INTO #visit VALUES('10001501299','TFRADMIN','11/5/13 4:47 PM','5W','LD');

    INSERT INTO #visit VALUES('10001501299','ENDISIN','11/8/13 12:52 PM',NULL,NULL);

    As for the rest of the question... not sure yet... but if you make it easy for people to recreate your table(s) and some data, it's much easier for others to answer...