I am looking for if else or case statement to select last week,last to last week,last month,last quarter and last year data.
And i need that in a variable. and then i will compare that variable to the column in my table.
tried below code.. but how will i get last- month,quarter and year data?
declare @period varchar(100)
IF(@period = 'Last Week')
SET @period = DATEADD(dd,-7,CONVERT(datetime,CONVERT(nvarchar(11),GETDATE())))
ELSE IF (@period='Last Two Weeks')
select * from department where joindate>@period