sql - How can I insert a row for each day within a date range? -


i have table , every row have id, date, , value column. want every time person accesses page on web site, stored procedure run insert row each day within range if day doesn't exist.

the date range 01/01/2012 until saturday before current day (the day page accessed). id auto-generate , value field remain null/blank.

for example, if accessed page today, want record in table every day between 01/01/2012 until 03/03/2012.

this gets days don't exist yet, , excludes rows after previous saturday.

;with d  (   select top (366) d = dateadd(day, row_number() on (order object_id), '20111231')   sys.all_objects ) insert dbo.[a table]([date])   select d d    d not in (select [date] dbo.[a table])   , d <= dateadd(day, 0-datepart(weekday, getdate()), getdate()); 

note assumed "reset" once calendar year rolled over.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -