NUmber of Patients in an A&E department every hour

Hi SQL Guru's,
I've got what for me is a tricky little problem. I want to be able to count the number of patients in our A&E department at every hour of every day.
I have access to the A&E Attendances tables that list the PatientID, ArrivalDateTime, DepartureDateTime etc so what I want to do is for example, look at how many people were in the department at 13:00hrs yesterday. This will be any patient that has arrived
before 13:00hrs and as yet does not have a departure date time. I want this to loop and do this calulation for every hour and every day between what ever start and end date parameters I pass into the query
Any help on this would be greatly appreciated
Many Thanks Guys
AntBai

Please try this: 
declare @current_date datetime = '2014-11-04 04:10'
declare @last13hrs datetime = @current_date - '13:00' --select @last13hrs
declare @Attendances table
( PatientID int, ArrivalDateTime datetime, DepartureDateTime datetime);
insert @Attendances
values
( 1, '2014-11-03 10:00', '2014-11-04 01:00'),
( 2, '2014-11-03 11:00', null),
( 3, '2014-11-03 18:00', '2014-11-04 03:00'),
( 4, '2014-11-03 23:10', '2014-11-04 04:00'),
( 5, '2014-11-03 23:10', null),
( 6, '2014-11-03 23:20', Null);
--This will be any patient that has arrived before 13:00hrs and as yet does not have a departure date time.
select
count(*) over() as cnt
from
@Attendances
where
ArrivalDateTime >= @last13hrs
and DepartureDateTime is null;
--more data to show
select
datediff(hh, ArrivalDateTime, DepartureDateTime ),
datediff(hh, ArrivalDateTime, @current_date )
from @Attendances;
T-SQL Articles
T-SQL e-book by TechNet Wiki Community
T-SQL blog

Similar Messages

  • What number do I call to update my phone every few months??

    What number do I call to update my phone every few months??

    If you mean getting updates for your operating system (Gingerbread, ice cream sandwich), there is no number to call. Updates come automatically to your phone. If you are referring to getting a new phone, there is no way you can do that every few months. You are bound to a two year contract with the phone(s) you have. There is nothing preventing you from buying a different phone at full cost, however.

  • My iphone camera used to number photographs continuously; now it starts at 001 every time. How can I reset it to number continuously again?

    My iphone camera used to number photographs continuously; now it starts at 001 every time.
    How can I reset it to number continuously again?

    Settings > Messages > Receive At > Caller ID and select your number

  • TS1368 I can not read my itune card number 1/2  off  $50.00 just by two hours ago

    I cann't read my itune card 1/2 numbers our gone this is a number on button of card pbh6063300000277635976  got it at hy vee in wascea minn

    See this support article:
    http://support.apple.com/kb/TS1292
    If you can't get the card to work after perusing that page, contact the iTunes Store Support; instructions are at the bottom of that article.
    Regards.
    Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Communities page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums and in the Apple Knowledge Base, before you post a question.

  • HT201232 I have called the support number given, was on hold for more than an hour and received quite unpleasant phone bill for trying to sort out AppStore mistake! Is there any other options of getting "support" apart from calling these telephone numbers

    My account was charged for buying app that I actually didn't buy. I was trying to sort out these mistake by calling the support number given (Russia). There was no other options like sending an email or calling some other number. I was on hold for one hour and a half! Is that normal for Apple support??? So apart from being charged for the app I haven't given my permission to buy, I also got a phone bill for calling the only support number available. Where can I submit my complain and what could be done about it?
    Thank you,
    Natalia

    There is an email way to do this. See here: https://getsupport.apple.com/ContactInfo.action
    The Russian Federation is one of the countries listed under Other.

  • I purchased a Student/Teacher addition 2 days ago and still cannot download for order number AD004080514EDAU. It is supposed to be 24 hours but there is still no progress

    I purchased a Student/Teacher addition 2 days ago and still cannot download for order number AD004080514EDAU.
    Adobe promised 24 hours - now 36 so what's happening

    Alicemarie if you are facing difficulties with your order then please contact our support team directly at Contact Customer Care.
    Did you utilize your e-mail address associated with your education organization when making your order?

  • Billing Document - Document Number X Time - The last document has the first hour

    Hi All ,
    We have a fail in synchronism between fields VBELN (Billing Document) and ERZET (Creation time) of table VBRK as seen below :
    The document VBELN 0490014130 has ERZET 10:54:28 – 01.03.2014
    The document VBELN 0490014131 has ERZET 10:53:26 – 01.03.2014
    The error occurs between Billing Documents processed by job and Billing Documents processed between dialog users
    Do you know any Note or adjustment Standard for this issue or a note for all Countries ?
    Tks Team ,

    Not sure whether it is for the same customer.  In normal circumstances, it could be due to couple of reasons like one billing document which has generated early would be normal process and the one which takes little bit extra time would involve some customization due to which table updation may take extra time.   Also these types of issues will happen only in batch jobs and if you generate individually, it wont happen.
    G. Lakshmipathi

  • Huge number of duplicate files in iTunes music library, every song twice!  Can I just uplug my external hard drive and clear all songs, then resync?

    iTunes seems to have a duplicate listing of every song that is on my removeable external USB hard drive.  Is there an easy way to remove these?  Every song is listed twice, but one of the listings gives an error when you try to access it.
    I haven't tried this yet, but can I just unplug the HD, then delete all of those songs, then plug it back in and let iTunes "find" them again?

    Try iTunes Folder Watch with its option to scan for dead tracks on startup. Alternatively...
    Lost & Found
    Create a playlist called Found, select everything in Music and drag it into the Found playlist. Create a smart playlist called Lost matching All the rules Playlist is Music and Playlist is not Found. Your "missing" tracks will be in this playlist. If it suits your purposes you can select them all with Ctrl-A then delete them with Ctrl-Shift-Delete.
    tt2

  • Time Machine Backs Up Same Number Of Files Every Time It Runs

    Thought I had TM sorted out on my new iMac (Snow Leopard), but it keeps exhibiting this behavior and I can't get it to stop. It backs up to an external HDD with plenty of space via FW800, connections are all good etc. I've run Disk Warrior on the boot disk, the TM disk and one other external drive that is included in the backup. TM HDD and the other one are both excluded from Spotlight & I've forced a re-index of the main HDD several times as well.
    The odd/persistent behavior is that TM backs up pretty much the exact same number of files from the other external HDD every hour. It's always the same whether the machine is idle or in use. Hoping the Great Pondini might be able to tell me why this might be happening or what I can do about it...

    Here's the report:
    Starting standard backup
    Backing up to: /Volumes/Backadoodle/Backups.backupdb
    No pre-backup thinning needed: 4.48 GB requested (including padding), 652.13 GB available
    Copied 4310 files (436.3 MB) from volume Big Music.
    Waiting for index to be ready (100)
    Copied 9372 files (3.7 GB) from volume Macintosh HD.
    No pre-backup thinning needed: 3.90 GB requested (including padding), 648.42 GB available
    Copied 4310 files (0 bytes) from volume Big Music.
    Waiting for index to be ready (100)
    Copied 9372 files (3.2 GB) from volume Macintosh HD.
    Starting post-backup thinning
    Deleted backup /Volumes/Backadoodle/Backups.backupdb/Kitch/2012-01-07-091200: 651.65 GB now available
    Post-back up thinning complete: 1 expired backups removed
    Backup completed successfully.

  • Operation_seq_num/ Department ID

    Hello All,
    Does any 1 have a idea regarding operation_seq_num and department_ID in table mtl_transaction_interface? I would like to understand on what bassis do we enter a value in these columns?
    I am doing a WIP Completion and Issue Components via API, and while doing the Issue components it is mandatory to enter both these fields. Is there any documentation available on this? what is the logic to populate this fields?
    When doing from the Application these fields are populated automatically based on the radio buttion= "All Material" in the Component issue form.
    any documentation will be really helpfull.
    TX in advance.
    Regards,
    K

    Hi,
    I did not use an API for this but the fields generic purpose is this..
    Operation Seq Number: This is the operation at which the material is given to the job this value comes from the BOM for the assembly where you give the operation at which the component is used. It is OK to give any operation seq present in the JOB (number defaulted form routing of this assembly)
    Department: This gets defaulted when you do WIP material transaction from front end based on the operation you have given and the department at which this operation is taken place. Since this is an import you might be asked to give in this value. In general department is important as the resource overheads are tied to it.

  • High Level Complaints contact number?

    Hi 
    I've got an issue that is turning into Groundhog Day which is covered in a different thread (service getting provisioned and that BT cancelling the order shortly afterwards, this is happened three times in two months now).  I'm not getting any response on trying to escalate, so in effect BT's complaints procedure isn't getting followed making it impossible to get a deadlock letter allowing me to go to arbitration.
    Does anyone have a current contact number for BT's High Level Complaints department?  Not too interested in a postal address, BT are a telecommunications company after all and if the only way of contacting them is mail.....
    Thanks in advance.
    Jimmy

    Hi Jimmy,
    I've checked our email queue and we still don't have one for the address registered in your profile. I'll drop you a PM and we can take it from there.
    Cheers
    David
    BTCare Community Mod
    If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
    We are sorry but we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-)

  • Possibility to change number delimitors according to language or choice

    I would like to see a possibility to change number delimitors according to language or by choice after they have been inserted or content placed. Example: if figures come in with commas like 22,33 and you need periods like 22.33 (or the other way around), it ought to be possible to select that or any part of a a table or an entire table and just choose which delimitor in the figure you want. Or that it changed automatically according to chosen language when language is set for the selected text (as language rules for which to use are different depending on the language), regardless of how it was formatted when typed or placed.

    It would require you to "tag" every 'real' number in  your text, wouldn't it?
    I would not trust an algorithm that makes the distinction for me. If I see decimal delimiters possibly used the wrong way, I search the entire document for both (digit).(digit) and (digit),(digit); then I make a judgement call on whether "n = 31.245" is about a large number of patients, and "p < 1,000" is a probability. I saw both of these in one single book to-day -- in the middle of correctly formatted numbers.
    Then again, tables could be enhanced to act like real miniature spreadsheets.

  • Got a call from 8207078890968 what kind of phone number is this?

    I got a call from 8207078890968 auto attendant saying my account was locked and to press a key to be connected with security department.  I hung up.  What kind of a number is 8207078890968?????

    Just got the same call. It said Express Mastercard and that my account had been locked and to press 1 to speak with someone. At that point I hung up. My husband, whose number is one number off from mine had gotten the call an hour or so before me and didn't answer. We both blocked the number.

  • You have access to No.Claim Has not received the message number redeem

    You have access to No.Claim Has not received the message number redeem
    It took a long time about 5 hours
    Please help

    Be patient. You don't get an immediately notification email. Record the Claim Number somewhere in case something goes wrong. It can take up to 72 hours. I got mine in about 54 hours.

  • Ranking response times for Fire Department

    Hello,
    I'm in the middle of powerpivot pro's online course, but I'm looking for a little feedback to see if I'm on the right track with a project. I work for a fire department and we collect the response times of our units. As you can guess, we have goals we measure
    against and I'm hoping powerpivot will be a good choice to work with. Simply put, for each incident (fire, medical) I create a response time using a calculated column in powerpivot window subtracting the arrival time from the dispatch time (format HH:MM:SS).
    I am populating the workbook with a database connection to our SQL database. I group the incidents using the unique incident number in a pivot table, so it list every unit that was on the run. My idea would be to create a measure listing each unit's response
    time, looking for the minimum time and compare the minimum against our goal. The result returns either true or false. 
    I"m working on the solution, but I'm just wondering if my idea sound plausible using powerpivot?
    I'm not looking for anyone to do my work, but looking for any suggestions to push me in the right direction.
    Thank you for looking , Brent

    Hello Paul, 
         The calendar table was something I just put in because of a lesson I had with Rob's course, so I was in the processing of adding it to the project as a means of reinforcing the lesson. I will take another look at our SQL database, but
    in the database, the incident and apparatus tables are primarily linked by the incident key. I will double check to see if the apparatuses in the table have another relationship with a look up table and I can change the data model. Initially, I was looking
    for the simplest model to start with and then build from there. 
          As far as the error, the min function is working correctly to find the minimum time of the incident, but I think my confusion comes with the grouping of the rows. As you can probably tell, there is one incident key for each fire call
    and many apparatus are assigned to the call with the incident key as the primary relationship. If I add all the incidents to the pivot table, it correctly identifies each incident as being met or not met. But, if I remove the incident keys from the pivot and
    just keep the months, the pivot table correctly filters down to the month and find the minimum of the entire month and I loose the details of each incident's value of met or not met. Thank to Rob, I understand what is happening, but not how to fix it (I'm
    finishing up the calendar table now and the X factors are next, which will probably help me with this issue).
    The reporting for now, is pretty simplistic. It is being able to identify each incident, if it met the goal and then able to report out of the incidents how many we made and how many we missed. If we had 1,000 calls and we made 500 of them, we would be at
    50%. The goal is a simple true or false based on the minimum time of the first arriving unit ( I used 200 seconds for this project). 
    I do have Excel 2013, so I can open the file. I created the original at home with 2010. 
    I hope that make sense.  Thank you for the help. I have the day off and I'm working through Rob's video course most of the day today.  Thanks, Brent

Maybe you are looking for

  • Error in setting Pricelist/Currency code

    I'm using Siebel Self-Services 8.1.1 and I always get the following error every for new session of the application: "Error in setting Pricelist/Currency code. Please contact System Administator". Anyone having an idea how to solve it? Thanks! /Jon-Er

  • Ultranav won't install after upgrade to Win 7

    I upgraded from XP to Win 7 Ultimate. When I try to install the Win 7-compliant driver from the Lenovo site, the OS tells me that it's not compliant and "fixes" the problem by installing generic drivers that, of course, don't allow me to modify the U

  • Target cost not appearing in process order

    Hi All, Please let me know the reasons for target cost not appearing in process order. Thanks, SAP PQ

  • Need Help!!  Cannot Create Table

    Hi, I just installed Oracle XE and APEX 4.0.2. I REALLY need to create an application with 3 tables where I can update these tables via a form like found in Application Express. The install and configuration went very smoothly until I went to create

  • How do i save audio books to a file then delete from phone

    How do I save an audio book to file then delete from my Iphone.