MEDITECH DR, NPR, MEDITECH Reporting, MEDITECH Reports, MEDITECH DR Reports, MEDITECH BI, MEDITECH Data Repository
I'm your host, John Sharpe, a MEDITECH Consultant living in Spokane, WA. Read more ...
Expand your network by connecting on these social media sites:
Sign up for the MEDITECH Reports Blog; details to attend MEDITECH workshops are sent out 1 week in advance to all MEDITECH Report blog subscribers.These MEDITECH Workshops are sponsored by Donna Carroll at the MEDITECH Community Bulletin
Ascii Table: For NPR Report Writer Loop Builder: For NPR Macros Key Codes: For CDS Attributes List Builder: For NPR Macros MT Report Names: For NPR Reports MT Structure Viewer: For Physicals Strings: Format & Sort
Current Articles | RSS Feed
When comparing a date time in SQL to a range of literal dates, we want to keep in mind that datetime is formatted as YYYY-MM-DD hh:mm:ss.nnn. The nnn stands for fractional seconds.
The T.ServiceDateTime is formatted as datetime '2010-07-26 10:03:56.000'. The CONVERT converts '07/25/2010' to '2010-07-25 00:00:00.000' & '07/31/2010' to '2010-07-31 00:00:00.000'.
Spot my problem now? The ServiceDateTime that is '2010-07-31 01:56:00.001' will not be included in my data set.
Fortunately, converting the field ServiceDateTime to '2010-07-31 00:00:00.000' resolves the problem when the dates are compared.
WHERE CONVERT(datetime, CONVERT(CHAR(8), T.ServiceDateTime, 112)) BETWEEN CONVERT( datetime, '07/25/2010') AND CONVERT(datetime, '07/31/2010')
Want an alert when the next post is published? Click the phone and Subscribe to the MEDITECH Reports Blog!
Allowed tags: <a> link, <b> bold, <i> italics