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 2000 Forums
 SQL Server Development (2000)
 Historical Snapshot

Author  Topic 

singularity
Posting Yak Master

153 Posts

Posted - 2008-04-04 : 11:19:38
I have a table like this:

Case_ID Assignment_Date Queue_ID
2677490 2008-04-02 16:15:53.480 1661
2677490 2008-04-03 09:14:20.690 1062
2678373 2008-04-02 16:38:06.153 1947
2678373 2008-04-02 16:40:08.027 1656
2678373 2008-04-03 09:36:56.923 1083
2678386 2008-04-02 16:38:25.777 68064
2678386 2008-04-02 16:39:56.277 1661
2678386 2008-04-03 09:05:15.940 1354
2678386 2008-04-03 09:37:08.500 601
2679229 2008-04-02 17:05:24.653 101
2679229 2008-04-02 17:05:25.997 1656

Basically, it captures every instance of a case being assigned to a queue. What I've been asked to do is to take a historical snapshot of all the cases that were assigned to queues 1656 and 1661 as of 7AM on 04/03/2008. Any ideas on how I would do that?

Thanks in advance.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-04-04 : 11:37:04
select *
from yourtable
where Assignment_Date >= '2008-04-03 07:00:00' and Queue_ID in (1656, 1656)

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2008-04-04 : 11:43:42
Spirit1...should this not be
"Assignment_Date <= '2008-04-03 07:00:00' " ????

>= would mean records added AFTER 7am...
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-04-04 : 11:46:11
doesn't as of date mean from that date?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

singularity
Posting Yak Master

153 Posts

Posted - 2008-04-04 : 13:13:47
spirit, that's not exactly what I'm looking for. I need cases that were still assigned to queues 1656 and 1661 as of 7AM, meaning the next entry on the log is after 7AM.

For example, the case below would need to be captured because it was still in queue 1661 as of 7AM on 4/3 (it did not leave that queue until 9:14am)

2677490 2008-04-02 16:15:53.480 1661
2677490 2008-04-03 09:14:20.690 1062
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-04-04 : 14:37:15
I think this is what you are after:
DECLARE @Case TABLE (Case_ID INT, Assignment_Date DATETIME, Queue_ID INT)

INSERT @Case
SELECT 2677490, '2008-04-02 16:15:53.480', 1661
UNION ALL SELECT 2677490, '2008-04-03 09:14:20.690', 1062
UNION ALL SELECT 2678373, '2008-04-02 16:38:06.153', 1947
UNION ALL SELECT 2678373, '2008-04-02 16:40:08.027', 1656
UNION ALL SELECT 2678373, '2008-04-03 09:36:56.923', 1083
UNION ALL SELECT 2678386, '2008-04-02 16:38:25.777', 68064
UNION ALL SELECT 2678386, '2008-04-02 16:39:56.277', 1661
UNION ALL SELECT 2678386, '2008-04-03 09:05:15.940', 1354
UNION ALL SELECT 2678386, '2008-04-03 09:37:08.500', 601
UNION ALL SELECT 2679229, '2008-04-02 17:05:24.653', 101
UNION ALL SELECT 2679229, '2008-04-02 17:05:25.997', 1656


SELECT
Case_ID,
Assignment_Date,
Queue_ID
FROM
(
SELECT
*,
(
SELECT
MIN(Assignment_Date)
FROM
@Case AS T
WHERE
T.Case_ID = A.Case_ID
AND T.Assignment_Date > A.Assignment_Date
) AS NextDate
FROM
@Case AS A
) AS Temp
WHERE
CAST('2008-04-03 07:00:00' AS DATETIME) BETWEEN Assignment_Date AND NextDate
AND Queue_ID IN (1656, 1661)

EDIT: reformated for screen width. :)
Go to Top of Page

singularity
Posting Yak Master

153 Posts

Posted - 2008-04-04 : 14:48:05
Thanks, Lamprey
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-04-04 : 16:52:21
If you are still looking, I think there is a sligh error. Check out the new WHERE clause:
WHERE
CAST('2008-04-03 07:00:00' AS DATETIME) BETWEEN Assignment_Date AND COALESCE(NextDate, CAST('99991231' AS DATETIME))
AND Queue_ID IN (1656, 1661)
Go to Top of Page

johnsql
Posting Yak Master

161 Posts

Posted - 2008-06-06 : 10:32:22
quote:
Originally posted by singularity

spirit, that's not exactly what I'm looking for. I need cases that were still assigned to queues 1656 and 1661 as of 7AM, meaning the next entry on the log is after 7AM.

For example, the case below would need to be captured because it was still in queue 1661 as of 7AM on 4/3 (it did not leave that queue until 9:14am)

2677490 2008-04-02 16:15:53.480 1661
2677490 2008-04-03 09:14:20.690 1062



I just wonder the definition of "AS OF"
"as of : used to show the time or date from which sth starts"
(Oxford Dictionary)

so the date criteria for should be

... where assignment_date >= '04/03/2008 07:00:00" ?
Go to Top of Page
   

- Advertisement -