SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Howtoget Same Second record & Same Location Record
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Najju565
Starting Member

2 Posts

Posted - 08/02/2012 :  02:41:57  Show Profile  Reply with Quote
Hi.. I need to get only records having Same datetime but can have second difference of 10 Seconds and has same location in SQL Server .. Pls help me ...
DATETIME ADMITID LOCATION
--------------------------------------------------------
7/29/2012 00:01:40 1 1F-E FRONT IN
7/29/2012 00:01:54 2 1F-E FRONT OUT
-----------------------------------------------------------------
7/29/2012 00:01:55 1 CHEN DLF 1 IN
7/29/2012 00:01:58 1 CHEN DLF 1 IN

--------SAME LOCATION AND SAME DATETIME and SECOND DIFFERENCE records only should get Displayed same as shown above and below records
7/29/2012 00:02:18 1 CHEN-DLF IN
7/29/2012 00:02:20 1 CHEN-DLF IN
---------------------------------------------------------------------
7/29/2012 00:03:06 1 BLR-WF-ITSVC-3F-NORTH(ENTRY)
7/29/2012 00:03:10 2 BLR-WF-ITSVC-2F-SOUTH(EXIT)

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 08/02/2012 :  09:49:32  Show Profile  Reply with Quote

SELECT t.*
FROM Table t
CROSS APPLY (
SELECT COUNT(1) AS Cnt
FROM Table
WHERE ADMITID = t.ADMITID
AND [DATETIME] > = DATEADD(ss,-10,t.[DATETIME])
AND [DATETIME] <= DATEADD(ss,10,t.[DATETIME]
)t1
WHERE Cnt >0


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Najju565
Starting Member

2 Posts

Posted - 08/03/2012 :  07:33:15  Show Profile  Reply with Quote
Thanks a lot.. It worked..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 08/03/2012 :  09:40:47  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000