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.
| Author |
Topic |
|
vegasvic
Starting Member
4 Posts |
Posted - 2005-10-13 : 15:28:02
|
| HelloI need to have a query search for records that are time stamped 30 minutes earlier than the current system time.here is the query I am usingSELECT item_id,item_desc,sum(print_quantity) as qtyFROM dbo.pathguide_pick_ticket_viewWHERE (print_date >= GETDATE() - 1) AND (location_id = 100004) AND (last_maintained_by = 'amazon_picks') OR(last_maintained_by = 'ecomm_picks')group by item_id ,item_descorder by item_id ascI am using this query in a VB6 program the will print a report of things printed in the last 30 min.Ideally I would like to pass a variable to set the time to diffrent intervals. I just need to know how to parse the date outthanksVgeas Vic |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-10-13 : 16:26:49
|
| Where did you come up withWHERE (print_date >= GETDATE() - 1)That will select items printed in the last 24 hours.Try this:WHERE (print_date >= dateadd(minute,-30,GETDATE()) )CODO ERGO SUM |
 |
|
|
vegasvic
Starting Member
4 Posts |
Posted - 2005-10-13 : 16:42:27
|
| the original request was for a 24 hour period. then they changed there minds and mow want every 30 min....I tried your suggestion but it did not work |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-10-13 : 18:05:34
|
| Well, dateadd(minute,-30,GETDATE()) returns the time 30 minutes before the current system time.Maybe your print_date column only contains the date without the time. If that is the case, I don't see hou you are going to find what you need.CODO ERGO SUM |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-14 : 00:52:41
|
| If print_date is DateTime Column, then try thisDateDiff(minute,print_date,GetDate())<=30MadhivananFailing to plan is Planning to fail |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2005-10-14 : 01:12:53
|
quote: Originally posted by madhivanan If print_date is DateTime Column, then try thisDateDiff(minute,print_date,GetDate())<=30MadhivananFailing to plan is Planning to fail
Michael's "WHERE (print_date >= dateadd(minute,-30,GETDATE()) )" is logically equivalent to this, but has the advantage of being able to use an index on the print_date column. By embedding print_date in the DateDiff function the ability to use an index is lost. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-14 : 01:29:33
|
Thanks blindman MadhivananFailing to plan is Planning to fail |
 |
|
|
vegasvic
Starting Member
4 Posts |
Posted - 2005-10-14 : 08:22:06
|
| thanks for all the input guys...the column is a datetime datatype. These both worked (yesterday I had a brain fade when I thought they did not, long day of staring at data)until i added the and (last_maintained_by = 'amazon_picks') OR(last_maintained_by = 'ecomm_picks')to the where clause then I recived results dates from yesterdaythis works i only get records from today within the last 30 minSELECT item_id,item_desc,sum(print_quantity) as qty,print_date,last_maintained_byFROM dbo.pathguide_pick_ticket_viewWHERE (print_date >= dateadd(minute,-30,GETDATE()) )AND (location_id = 100004)group by item_id ,item_desc,print_date,last_maintained_byorder by qty desc2005-10-14 08:21:17.0002005-10-14 08:20:30.0002005-10-14 08:21:10.0002005-10-14 08:20:13.0002005-10-14 08:20:19.0002005-10-14 08:20:36.0002005-10-14 08:20:24.0002005-10-14 08:20:43.0002005-10-14 08:21:18.0002005-10-14 08:20:10.0002005-10-14 08:20:15.0002005-10-14 08:21:33.000this returns records from yesterdaySELECT item_id,item_desc,sum(print_quantity) as qty,print_date,last_maintained_byFROM dbo.pathguide_pick_ticket_viewWHERE (print_date >= dateadd(minute,-30,GETDATE()) )AND (location_id = 100004) and(last_maintained_by = 'amazon_picks') OR(last_maintained_by = 'ecomm_picks')group by item_id ,item_desc,print_date,last_maintained_byorder by qty desc2005-10-13 09:44:19.0002005-10-13 09:44:32.0002005-10-13 09:44:28.0002005-10-13 09:44:15.0002005-10-13 09:44:41.0002005-10-13 09:44:49.0002005-10-13 09:44:23.0002005-10-13 09:44:37.0002005-10-13 09:44:45.0002005-10-13 09:44:53.0002005-10-13 16:36:14.0002005-10-13 16:36:34.0002005-10-13 16:36:10.0002005-10-13 16:36:24.0002005-10-13 16:36:02.0002005-10-13 16:36:19.0002005-10-13 16:36:38.000this is running against a view just as an fyithanks for the help |
 |
|
|
|
|
|
|
|