0

I have two fields which stores month and day separately. I have a requirement where I need to check the month and day fields(in the format MM/DD) should lie between two dates. For example, if I have month and day fields stored as (02/11), then if the user passes from and to dates as 02/11/2012(MM/DD/YYYY) to 02/28/2014, then I need get that record(02/11).

Kindly provide your inputs on how to achieve this in T-Sql or SQL Server.

sarayucm
  • 126
  • 3
  • 14
  • 1
    http://stackoverflow.com/questions/13617175/find-a-date-between-two-dates-in-t-sql – kleinohad Dec 31 '14 at 06:24
  • http://stackoverflow.com/questions/5125076/sql-query-to-select-dates-between-two-dates – kleinohad Dec 31 '14 at 06:24
  • If the FROM date is 11 Feb 2012 and TO date is 28 Feb 2014, then the given range of dates is more than a year and the result would be all your records, wouldn't it? Please provide a good sample of data and few examples of FROM and TO dates together with expected results. – Vladimir Baranov Dec 31 '14 at 11:19

1 Answers1

1

FOR SQL SERVER 2012

   IF (select  CONCAT(month,'/',day)) 
FROM tbl) between LEFT(date1,5) and LEFT(date2,5)
BEGIN 
PRINT CONCAT(month,'/',day) 
END
Dudi Konfino
  • 1,126
  • 2
  • 13
  • 24