Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Missing Dates in sql 2005 table

Author  Topic 

cmrrive
Starting Member

6 Posts

Posted - 2012-03-25 : 10:23:40
My table looks like this


Bus,GLAcct,Amount,Date
1,410100, 200,2012-01-01
2,410100, 250,2012-01-02
3,410100, 300,2012-01-04

I need to add (missing date 2012-01-03) and keep the same
date for previous record (2,410100,250,2012-01-02). This will apply for any missing date on the table.

Any help please!!!

miguel

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-03-25 : 12:05:22
You need a calendar table for this, a table that just contains sequential dates from a starting date to an ending date. Once you have that, it's a simple left join or not exists to find the dates that don't exists in your table.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-26 : 13:13:21
see one here

http://visakhm.blogspot.com/2010/02/generating-calendar-table.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -