Tuesday, July 30, 2013

SQL Server - T-SQL for setting Date

DECLARE @DayOfMonth TINYINT SET @DayOfMonth = 31
DECLARE @Month TINYINT SET @Month = 3
DECLARE @Year INTEGER SET @Year = YEAR(GETDATE()) + 1
DECLARE @NextWaiverYear AS DATETIME2


 ------------------------------------
SET @NextWaiverYear = (Select DateAdd(day, @DayOfMonth - 1,
          DateAdd(month, @Month - 1,
              DateAdd(Year, @Year-1900, 0))))

SELECT DISTINCT TblSlotWaiverYear.WaiverYrID, TblSlotWaiverYear.Description AS SlotWaiverYearDescription
FROM            TblSlotWaiverYear WHERE EndDt <= @NextWaiverYear
Post a Comment