October 23, 2016 at 9:40 am
If am running today query ( 10/23/2016), then I need get data from following dates 10/22/2016,10/23/2016.can anyone tell me an idea for how to do it?
my query is
SELECT TOP 1000 [action_id]
,DBO.UtcToLocal(creation_date) as Creation_Date
,[event_name]
,[person_num]
FROM [bcore].[dbo].[TEST] WHERE person_num = '00010167'
expected query output:
1684862016-10-22 15:41:22.823CLOCK_IN00010167
1687952016-10-22 19:47:22.823CLOCK_OUT00010167
1688862016-10-23 10:39:22.823CLOCK_IN00010167
1689182016-10-23 12:25:22.823CLOCK_OUT00010167
October 23, 2016 at 10:31 am
Something like this:
SELECT *
FROM
(SELECT 1 as PersonID, '2016-10-21 11:00' as evntTime, 'CLOCK_IN' as evntType
UNION ALL
SELECT 1, '2016-10-21 20:45', 'CLOCK_OUT'
UNION ALL
SELECT 1, '2016-10-22 3:45', 'CLOCK_IN'
UNION ALL
SELECT 1, '2016-10-22 12:45', 'CLOCK_OUT'
UNION ALL
SELECT 2, '2016-10-23 11:00', 'CLOCK_IN') x
WHERE x.evntTime > GETDATE()-1;
You may need to tweak the WHERE clause so it returns exactly what you want.
October 24, 2016 at 5:25 am
pietlinden (10/23/2016)
You may need to tweak the WHERE clause so it returns exactly what you want.
Your answer is perfect if you need to filter for the past 24 hours. As for the original post it looks like the result must match today and yesterday (whole day), so you'll need to filter only on the DATE part. That would lead to altering the WHERE clause to:
...
WHERE x.evntTime > cast(GETDATE()-1 as date)
October 25, 2016 at 7:23 am
HanShi (10/24/2016)
...
WHERE x.evntTime > cast(GETDATE()-1 as date)
since evntTime seems to be DATETIME datatype, wouldn't that leave an implicit conversion in the execution to compare it to the calculated DATE value? If you want to avoid the conversion, maybe something like:
WHERE x.evntTime > DATEADD(day, DATEDIFF(day, 1, GETDATE()),0)
October 25, 2016 at 7:46 am
Chris Harshman (10/25/2016)
HanShi (10/24/2016)
...
WHERE x.evntTime > cast(GETDATE()-1 as date)
since evntTime seems to be DATETIME datatype, wouldn't that leave an implicit conversion in the execution to compare it to the calculated DATE value? If you want to avoid the conversion, maybe something like:
WHERE x.evntTime > DATEADD(day, DATEDIFF(day, 1, GETDATE()),0)
Your absolutely right 😎
October 31, 2016 at 4:53 am
Hi,
I need to display tomorrow date result also . could you guys guide me achieve the same .
October 31, 2016 at 5:42 am
philand3 (10/31/2016)
Hi,I need to display tomorrow date result also . could you guys guide me achieve the same .
Here's a post with some common date routines. It should be a big help. http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply