Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate missing dates + Sql Server (SET BASED)
    primarykey
    data
    text
    <p>I have the following </p> <pre><code>id eventid startdate enddate 1 1 2009-01-03 2009-01-05 1 2 2009-01-05 2009-01-09 1 3 2009-01-12 2009-01-15 </code></pre> <p>How to generate the missing dates pertaining to every eventid?</p> <p>Edit: <strong>The missing gaps are to be find out based on the eventid's. e.g. for eventid 1 the output should be 1/3/2009,1/4/2009,1/5/2009.. for eventtype id 2 it will be 1/5/2009, 1/6/2009... to 1/9/2009 etc</strong></p> <p>My task is to find out the missing dates between two given dates.</p> <p>Here is the whole thing which i have done so far</p> <pre><code>declare @tblRegistration table(id int primary key,startdate date,enddate date) insert into @tblRegistration select 1,'1/1/2009','1/15/2009' declare @tblEvent table(id int,eventid int primary key,startdate date,enddate date) insert into @tblEvent select 1,1,'1/3/2009','1/5/2009' union all select 1,2,'1/5/2009','1/9/2009' union all select 1,3,'1/12/2009','1/15/2009' ;with generateCalender_cte as ( select cast((select startdate from @tblRegistration where id = 1 )as datetime) DateValue union all select DateValue + 1 from generateCalender_cte where DateValue + 1 &lt;= (select enddate from @tblRegistration where id = 1) ) select DateValue as missingdates from generateCalender_cte where DateValue not between '1/3/2009' and '1/5/2009' and DateValue not between '1/5/2009' and '1/9/2009' and DateValue not between '1/12/2009'and'1/15/2009' </code></pre> <p>Actually what I am trying to do is that, I have generated a calender table and from there I am trying to find out the missing dates based on the id's</p> <p>The ideal output will be</p> <pre><code>eventid missingdates 1 2009-01-01 00:00:00.000 1 2009-01-02 00:00:00.000 3 2009-01-10 00:00:00.000 3 2009-01-11 00:00:00.000 </code></pre> <p>and also it has to be in SET BASED and the start and end dates should not be hardcoded</p> <p>Thanks in adavnce</p>
    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.
 

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