need to get data based on a date plus or minus four hours from another date

Attached is a report.  i need to pull the medication 'taken time' based on four hours plus or minus the procedure start time.

The procedure start time is a calculated field based on a given event.  The formula is on the report called procedure start.

Example:  Test Heidi had a surgery on 6/10.  There are two taken times showing, because the report is pulling all medications she has ever been given.  I want just the medications given +/- four hours from the procedure start time.

Thank you for your assistance.
Becky EdwardsEpic Clarity DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony PerkinsCommented:
You may find members here somewhat hesitant about downloading a file here, especially one.that is not txt or pdf.  So if you are trying to describe something here you may be better off pasting it in as an image.
Anthony Perkins,

 Posting the actual report (RPT) file is usually the best option with a question like this, as long as the report doesn't include any "sensitive" information.  That way we can see the report structure, etc. for ourselves.

 FWIW, in this case the file d/l'ed with an HTML extension, but it is actually a CR report file.  I'm not sure what happened there.  I recently read that EE was having problems with some file uploads, so maybe EE changed the extension.

Within the report, or within the code providing data for the report, you can probably use a function datediff to get the number you want.

datediff has 3 parameters - the units, the first datetime, and the last datetime. Note that the format of the units can vary - in SSRS "m" indicates months whereas in T-SQL you use just an m - no quotes!

So in your case you have a patient who had surgery on June 10 but you must also have a time. So we'll assume that surgery was started at 2014:06:10 15:00:00 (3 pm). This can be called tiSurgery.

In a query for all medications administered +/- four hours of that time one would be comparing a medication administration datetime from a table, which can be called tiMedAdmin, in the following way:

abs (  datediff(hour, tiSurgery, tiMedAdmin)  )  < 4

Values where tiMedAdmin is before tiSurgery will be negative, hence the use of the abs() function (absolute value).



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.


 Group selection may work.  Go to Report > Selection Formulas > Group and enter the following formula:

 DateAdd ("h", -4, Maximum ({@Proc Start}, {ORDER_MED.ORDER_MED_ID})) to
 DateAdd ("h", 4, Maximum ({@Proc Start}, {ORDER_MED.ORDER_MED_ID}))

 That uses DateAdd to subtract 4 hours from the start time and add 4 hours, to create the range.

 I am assuming that ORDER_MED_ID is a unique ID for every time a patient is given any medication, as opposed to an ID for the medications themselves.  IOW, you do not have the same ORDER_MED_ID for every time a patient is given medication X.  (I hope that made sense :-)

 If the group selection formula works, note that group selection is really suppression.  The report is still reading all of the same records (it has to, in order to get the value for {@Proc Start}, and then determine if that group should be included).  So, if you use any CR summaries, they will include the groups that are not shown.  Also, if the group tree is visible when someone runs the report, the tree will include the groups that are not shown, but if someone tries to select one of them, CR will just move to the nearest visible group.

 If the group selection works, but, for example, you want to use summaries, or the report is just reading a lot of extra data that is then not shown, and that slows the report down; then you may need to do this by writing a query that selects the correct data before it is sent to the report, and using that as the datasource.  That would be the most efficient solution.

Becky EdwardsEpic Clarity DeveloperAuthor Commented:
Actually, Mike, this is what I was looking for. A way to create a formula based on two fields.  I may have problems because one of the fields is actually a formula, but I will cross that road when I get there.

Thank you,

Then ask that question too (separately). Post a comment here saying you're starting another question, with the question title, and people who've seen this one can help you there too.

As for the field being a formula, do you mean that it is an expression involving two or more other fields? If so, you might get something like this:

abs (  datediff(hour, tiSurgery, (tiMedStart + (3 * tiMedInterval) ) )  )  < 4

where you might be looking at a start time and a number of intervals after (where meds are given at each interval)


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB Reporting Tools

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.