Query for how to add the missing dates in sql

后端 未结 3 1251
臣服心动
臣服心动 2021-01-19 15:18

need to know how to add the date missing with null data in the corresponding field

**05/28/2012    NULL
05/29/2012  NULL
05/30/2012  NULL
05/30/2012  Break          


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-19 16:03

    Declare @stDate datetime='05/28/2012'
    declare @eddate datetime='06/14/2012'
    select DATEADD(day,number,@stdate) from master..spt_values where type='P'
    and DATEADD(day,number,@stdate) <= @eddate
    

    Here just join this result with your table on dates column to get the missing dates

提交回复
热议问题