943,852 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 303
  • MS SQL RSS
Aug 3rd, 2009
0

statement

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
carsein is offline Offline
5 posts
since Aug 2009
Aug 3rd, 2009
0

Re: statement

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.
Reputation Points: 10
Solved Threads: 9
Junior Poster
VIeditorlover is offline Offline
137 posts
since Dec 2007
Aug 3rd, 2009
0

Re: statement

I mean the difference between timestamp is 3 sec(or any given value).
Reputation Points: 10
Solved Threads: 0
Newbie Poster
carsein is offline Offline
5 posts
since Aug 2009
Aug 3rd, 2009
0

Re: statement

So you have many records and you want to see only pairs of rows created in less than 3 sec time window, right?
Reputation Points: 10
Solved Threads: 9
Junior Poster
VIeditorlover is offline Offline
137 posts
since Dec 2007
Aug 3rd, 2009
0

Re: statement

yes..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
carsein is offline Offline
5 posts
since Aug 2009
Aug 3rd, 2009
0

Re: statement

Try this:
sql Syntax (Toggle Plain Text)
  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. )
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Add columns in a table
Next Thread in MS SQL Forum Timeline: using sql with textbox structure





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC