Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had a different interpretation of the question: "how to generate all the dates between a certain range?"</p> <p>Here's a solution to that:</p> <pre><code>--define start and end limits Declare @todate datetime, @fromdate datetime Select @fromdate='2009-03-01', @todate='2009-04-10' ;With DateSequence( Date ) as ( Select @fromdate as Date union all Select dateadd(day, 1, Date) from DateSequence where Date &lt; @todate ) --select result Select * from DateSequence option (MaxRecursion 1000) </code></pre> <p>There is a nice <a href="http://smehrozalam.wordpress.com/2009/06/09/t-sql-using-common-table-expressions-cte-to-generate-sequences/" rel="nofollow noreferrer">article</a> that shows how to generate sequences (numbers, dates, times) using CTEs.</p> <hr> <p><strong>Edit:</strong></p> <p>After clarification, the issue seems to be the date format being input: dd/mm/yyyy. </p> <p>SQL Server expects the format mm/dd/yyyy. </p> <p>I would simply transform it before running the select statement:</p> <pre><code>-- Assuming two variables, @inputFromDate and @inputToDate, in the format of dd/mm/yyyy... declare @fromDate varchar(10), @toDate varchar(10) set @fromDate = substring(@inputFromDate, 3, 2) + '/' + substring(@inputFromDate, 1, 2) + '/' + substring(@inputFromDate, 7, 4) set @toDate = substring(@inputToDate, 3, 2) + '/' + substring(@inputToDate, 1, 2) + '/' + substring(@inputToDate, 7, 4) select * from SomeTable where dateCol &gt;= @fromDate and dateCol &lt; @toDate -- you can change the &lt; or &gt;= comparisons according to your needs </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload