Saturday 26 January 2019

how to return last month records from huge data row

DECLARE @StartDate DATETIME, @EndDate DATETIME   
SET @StartDate = DATEADD(mm, DATEDIFF(mm, 0, getdate()) - 1, 0)   
SET @EndDate = DATEADD(dd, -1, DATEADD(mm, 1, @StartDate))

SELECT @StartDate,@EndDate
SELECT Name FROM Employee WHERE date_created BETWEEN @StartDate AND @EndDate