Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Point of time

Author  Topic 

zrw
Starting Member

4 Posts

Posted - 2012-06-26 : 09:45:34
Hi, I am having one of those days, I just cant think...


I have the following fields LoggedDate,ResolvedDate,ID

I would like to list all the records that were open at a point in time...

eg ResolvedDate of 1753 or resolved after or before the selected date
and logged before the selected date

r1 10/02/2010 11:53:53 1/01/1753 00:00:00
r2 11/02/2010 11:53:53 11/02/2010 11:00:00
r3 12/02/2010 11:53:53 14/02/2010 13:00:00
r4 13/02/2010 11:53:53 15/02/2010 09:00:00
r5 14/02/2010 11:53:53 1/01/1753 00:00:00

Therefore if i select the 12/02/2010 it will count r1 and r3 only

Hope this is enough info?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-26 : 11:50:24
WHERE LoggedDate <= '20101202'
and (ResolvedDate >= '20101202' or ResolvedDate = '17530101')

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-06-26 : 11:58:43
quote:
resolved after or before the selected date
Does that mean you only want Resolved dates not equal to the selected date (12/02/2010) or can that predicate really be ignored?
Go to Top of Page

zrw
Starting Member

4 Posts

Posted - 2012-06-27 : 08:47:50
jimf i tried that and I get the correct logged date, but the resolve date only returns 1753 not and job that was added prior to the date but closed after the selected date.

Lamprey if the call was logged prior to the selected date, though closed after the selected date then i want to see it...
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-27 : 09:14:28
Slight change to mine
WHERE LoggedDate < '20101302'
and (ResolvedDate >= '20101202' or ResolvedDate = '17530101')

I didn't take the time element into consideration! This gives what you originally asked for.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -