-2

I know there are a lot of solutions to this but I am looking for a simple query to get all the dates between two dates.

I cannot declare variables.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Nisha Nethani
  • 109
  • 1
  • 1
  • 11
  • 1
    **AT LEAST** show us your table structure, some sample data in that table, and **your efforts** to select the values you want .... after all, we **CANNOT** see your screen, nor read your mind - you have to **SHOW & TELL US!** – marc_s Feb 14 '16 at 11:05

1 Answers1

0

As per the comment above, it's just guesswork without your table structures and further detail. Also, are you using a 3NF database or star schema structures, etc. Is this a transaction system or a data warehouse?

As a general answer, I would recommend creating a Calendar table, that way you can create multiple columns for Working Day, Weekend Day, Business Day, etc. and add a date key value, starting at 1 and incrementing each day.

Your query then is a very simple sub-select or join to the table to do something like

SELECT date FROM Calendar WHERE date BETWEEN <x> AND <y>

How to create a Calender table for 100 years in Sql

There are other options like creating the calendar table using iterations (eg, as a CTE table) and linking to that.

SQL - Create a temp table or CTE of first day of the month and month names

Community
  • 1
  • 1
Pete
  • 59
  • 4