0
votes

I have to get the data from a table between two dates.

The table does not have the date-format column where as it has two columns one for month and the other for year.

ID      UsrId       Month  Year  
212175  135564934   6      2016
212175  135564934   11     2013
212175  135564934   3      2014
212175  135564934   7      2015
212175  135564934   2      2016
212175  135564934   1      2016

I would like to get the rows between two dates(mm/yyyy) like from 01/2014 to 12/2016.

This should be in a stored procedure where it is taking two input parameters as begindate and enddate.

Thanks!

1
What have you tried? You will have to convert those two columns into a date so you can actually use them. I would suggest that using a date column would be a MUCH better approach from the beginning instead of a column for different date parts. - Sean Lange

1 Answers

2
votes

A simple way is to use arithmetic:

where year * 100 + month between 201410 and 201612

If you want date arithmetic:

where datefromparts(year, month, 1) between '20141001' and '20161201'