Show data from last 24 Hours from current (today) date in SQL Server

ashish007
 
on May 16, 2021 01:57 AM
461 Views

when i have run the 1 quey no data show

With cte AS(
SELECT top 6  ROW_NUMBER() OVER(PARTITION BY c.u_id ORDER BY c.u_id DESC) AS RowNum , a.to_id, c.*, a.from_id,  b.id as 'bid', c.u_id as 'cuid' from tblfrequst a 
             join tbluserinfo b on a.to_id=b.id
             join story c on c.u_id=b.id
             where a.from_id=10 and a.request_status='AC' 
             UNION
             select top 6  ROW_NUMBER() OVER(PARTITION BY c.u_id ORDER BY c.u_id DESC) AS RowNum, a.to_id,c.*, a.from_id, b.id, c.u_id from tblfrequst a 
             join tbluserinfo b on a.from_id=b.id 
            join story c on c.u_id=b.id
             where a.to_id=10 and a.request_status='AC' )
SELECT * FROM cte WHERE RowNum < =1 and DATE_TIME > DATEADD(day, -1, GETDATE()) order by st_id desc

 

SELECT * 
FROM STORY
WHERE DATE_TIME > DATEADD(day, -1, GETDATE())
Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on May 16, 2021 11:25 PM

Use below query.

SELECT *
FROM STORY
WHERE DATE_TIME BETWEEN DATEADD(HOUR, -24, GETDATE()) AND GETDATE()