Wednesday, December 31, 2014

Check month and day fields lies between two dates

Something like below? if you have reocrds for month of Feb in 2013. That will also come in result here. Because you have no Year information



CREATE TABLE #T (
MyMonth INT
,Myday INT
)
INSERT #T
select 2,11 union
select 4,11 union
select 2, 15 union
select 1, 20
DECLARE @StartDate DATE
SET @StartDate = '02/11/2012'
DECLARE @EndDate DATE
SET @EndDate = '02/28/2012'
SELECT *
FROM #t
WHERE MyMonth = MONTH(@StartDate)
AND myday BETWEEN day(@StartDate) AND day(@EndDate)





-Vaibhav Chaudhari


No comments:

Post a Comment