title: SQL Day of month when more than 24/28 days in a month
body: <p>I have a column, where users can insert the number of day for the month. Lets call the column DAY_OF_PERIOD, numbers 1-31 can be inserted there.</p>
  
  <p>I wonder what should happen when number 31 is inserted for example. But the month only has 28 days. It is still required for the numbers 29, 30 and 31 to appear in the selection when the query is started on the 28th (in case it is the last day of month)</p>
  
  <p>This would work when every month had the same number of days :p
  DAY_OF_PERIOD=dayofmonth(sysdate) </p>
  
  <p>Does anybody have an elegant solution for this?</p>
  
  <p>Best regards
  A</p>
  
  <p>EDIT:
  Added more info</p>
  
  <p>the user first inserts the frequency flag: daily, weekly, monthly. And then based on the first flag the day_of_period option means different things. 1-7 (weekly) or 1-31 (monthly). And also some other information for scheduling. And based on that information the table is looped, for example, every hour. So when the user enters a 31 in there (with a monthly flag), i have to include it in the query once every month and on the 31st day.</p>