select * from tb t where not exists(select 1 from tb where datediff(dd,dtdatetime,t.dtdatetime)=0 and suserid=t.suserid and dtdatetime>t.dtdatetime)
select * from tb t where not exists(select 1 from tb where datediff (dd,dtdatetime,t.dtdatetime)=0 and suserid=t.suserid and dtdatetime>t.dtdatetime)
IF OBJECT_ID('tempdb..#temp', 'u') IS NOT NULL DROP TABLE #temp GO CREATE TABLE #temp ( dtDateTime DATETIME, sUserID VARCHAR(10) ) INSERT #temp select '2011-06-04 08:19:10.210', 'A' UNION ALL select '2011-06-04 08:19:10.143', 'A' GO --SQL: SELECT DISTINCT * FROM #temp T WHERE NOT EXISTS( SELECT 1 FROM #temp WHERE CONVERT(VARCHAR(23), dtDateTime, 120) = CONVERT(VARCHAR(23), T.dtDateTime, 120) AND dtDateTime < T.dtDateTime )--RESULT: /* dtDateTime sUserID 2011-06-04 08:19:10.143 A */
select distinct convert(varchar(100),dtDateTime,120) as dtDateTime,sUserID
select distinct convert(varchar(19),dtDatetime,120) as dtDatetime,sUserID from Log_Schedule
(dd,dtdatetime,t.dtdatetime)=0 and suserid=t.suserid and dtdatetime>t.dtdatetime)
DROP TABLE #temp
GO
CREATE TABLE #temp
(
dtDateTime DATETIME,
sUserID VARCHAR(10)
)
INSERT #temp
select '2011-06-04 08:19:10.210', 'A' UNION ALL
select '2011-06-04 08:19:10.143', 'A'
GO
--SQL:
SELECT DISTINCT *
FROM #temp T
WHERE NOT EXISTS(
SELECT 1 FROM #temp
WHERE CONVERT(VARCHAR(23), dtDateTime, 120) = CONVERT(VARCHAR(23), T.dtDateTime, 120)
AND dtDateTime < T.dtDateTime
)--RESULT:
/*
dtDateTime sUserID
2011-06-04 08:19:10.143 A
*/
from Log_Schedule