statement

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2009
Posts: 5
Reputation: carsein is an unknown quantity at this point 
Solved Threads: 0
carsein carsein is offline Offline
Newbie Poster

statement

 
0
  #1
Aug 3rd, 2009
hi...I've tried to think about this for 2 days but I can't really find the solution. Hope anyone can help. What statement should I write for this:There is a table of Parcel. In the table there are ParcellId and the timestamp. I have to select parcels that have the time between two parcells is only less than 3 seconds. Others less than 3 sec should be ignored.
Last edited by carsein; Aug 3rd, 2009 at 5:16 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 97
Reputation: VIeditorlover is an unknown quantity at this point 
Solved Threads: 5
VIeditorlover's Avatar
VIeditorlover VIeditorlover is offline Offline
Junior Poster in Training

Re: statement

 
0
  #2
Aug 3rd, 2009
Are talking about a form of soft realtime? Please try to explain why is 3s limit so important for you, maybe it would be much easier to help you.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 5
Reputation: carsein is an unknown quantity at this point 
Solved Threads: 0
carsein carsein is offline Offline
Newbie Poster

Re: statement

 
0
  #3
Aug 3rd, 2009
I mean the difference between timestamp is 3 sec(or any given value).
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 97
Reputation: VIeditorlover is an unknown quantity at this point 
Solved Threads: 5
VIeditorlover's Avatar
VIeditorlover VIeditorlover is offline Offline
Junior Poster in Training

Re: statement

 
0
  #4
Aug 3rd, 2009
So you have many records and you want to see only pairs of rows created in less than 3 sec time window, right?
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 5
Reputation: carsein is an unknown quantity at this point 
Solved Threads: 0
carsein carsein is offline Offline
Newbie Poster

Re: statement

 
0
  #5
Aug 3rd, 2009
yes..
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,205
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is online now Online
.NET Enthusiast

Re: statement

 
0
  #6
Aug 3rd, 2009
Try this:
  1. --Create a simulation table
  2. IF OBJECT_ID('ParcelTest', 'U') IS NOT NULL DROP TABLE ParcelTest
  3. CREATE TABLE ParcelTest
  4. (
  5. ID INT identity(1000, 1) PRIMARY KEY,
  6. ShipDate DATETIME,
  7. Name VARCHAR(30)
  8. )
  9. GO
  10. --Create test data
  11. DECLARE @DATETIME DATETIME
  12. SET @DATETIME = FLOOR(Cast(GetDate() as FLOAT))
  13.  
  14. INSERT INTO ParcelTest (ShipDate, Name) VALUES (DateAdd(SECOND, -40, @DATETIME), 'Parcel')
  15. INSERT INTO ParcelTest (ShipDate, Name) VALUES (@DATETIME, 'Parcel')
  16. INSERT INTO ParcelTest (ShipDate, Name) VALUES (DateAdd(SECOND, 1, @DATETIME), 'Parcel')
  17. INSERT INTO ParcelTest (ShipDate, Name) VALUES (DateAdd(SECOND, 3, @DATETIME), 'Parcel')
  18. INSERT INTO ParcelTest (ShipDate, Name) VALUES (DateAdd(SECOND, 70, @DATETIME), 'Parcel')
  19.  
  20. GO
  21.  
  22. --Here is the meat of the question:
  23. DECLARE @secondsBetween INT
  24. SET @secondsBetween = 3
  25.  
  26. SELECT *
  27. FROM ParcelTest
  28. WHERE EXISTS
  29. (
  30. SELECT *
  31. FROM ParcelTest As x
  32. WHERE x.ID <> ParcelTest.ID AND ABS(DATEDIFF(SECOND, ParcelTest.ShipDate, x.ShipDate)) <= @secondsBetween
  33. )
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC