| | |
statement
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2009
Posts: 5
Reputation:
Solved Threads: 0
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.
Try this:
sql Syntax (Toggle Plain Text)
--Create a simulation table IF OBJECT_ID('ParcelTest', 'U') IS NOT NULL DROP TABLE ParcelTest CREATE TABLE ParcelTest ( ID INT identity(1000, 1) PRIMARY KEY, ShipDate DATETIME, Name VARCHAR(30) ) GO --Create test data DECLARE @DATETIME DATETIME SET @DATETIME = FLOOR(Cast(GetDate() as FLOAT)) INSERT INTO ParcelTest (ShipDate, Name) VALUES (DateAdd(SECOND, -40, @DATETIME), 'Parcel') INSERT INTO ParcelTest (ShipDate, Name) VALUES (@DATETIME, 'Parcel') INSERT INTO ParcelTest (ShipDate, Name) VALUES (DateAdd(SECOND, 1, @DATETIME), 'Parcel') INSERT INTO ParcelTest (ShipDate, Name) VALUES (DateAdd(SECOND, 3, @DATETIME), 'Parcel') INSERT INTO ParcelTest (ShipDate, Name) VALUES (DateAdd(SECOND, 70, @DATETIME), 'Parcel') GO --Here is the meat of the question: DECLARE @secondsBetween INT SET @secondsBetween = 3 SELECT * FROM ParcelTest WHERE EXISTS ( SELECT * FROM ParcelTest As x WHERE x.ID <> ParcelTest.ID AND ABS(DATEDIFF(SECOND, ParcelTest.ShipDate, x.ShipDate)) <= @secondsBetween )
![]() |
Similar Threads
- missing return statement (Java)
- MySQL LIKE statement (MySQL)
- loop in main function to an "if" statement (C++)
- Switch Case Statement (Java)
- run sql statement in asp (ASP)
- switch/case statement (C++)
- change statement (JSP)
- Reading MSWord Document through an ASP Statement (ASP)
Other Threads in the MS SQL Forum
- Previous Thread: Add columns in a table
- Next Thread: using sql with textbox structure
| Thread Tools | Search this Thread |






