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.
| Author |
Topic |
|
rohcky
Starting Member
38 Posts |
Posted - 2007-10-19 : 08:55:25
|
| Is it possible to fill in missing dates dynamically in SQL Server? If I had recordsDate----------10/3/2007 10/4/2007 10/9/2007I want a way to add records10/5/200710/6/200710/7/200710/8/2007dynamically. |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2007-10-19 : 09:08:28
|
| If you're trying to show that there is nothing for those days, you're better off with a calendar table that has all the dates and then left joining it to your tables.e.g.,SELECT t1.LName,t1.FName,t2.DATEFROM DateTable t2LEFT JOIN yourtable t1ON t2.date = t1.dateJim |
 |
|
|
rohcky
Starting Member
38 Posts |
Posted - 2007-10-19 : 09:31:47
|
| I'm actually trying to fill in data to get inventory on a daily basis.Right now it looks like:Date Inv----------------10/3/2007 1010/4/2007 810/9/2007 6What I want to do is fill in the missing dates and add the inv amount from the previous date (which I already know how to procure).Date Inv----------------10/3/2007 1010/4/2007 810/5/2007 810/6/2007 810/7/2007 810/8/2007 810/9/2007 6The problem with left joining to a calendar table is the function used to fill in the missing inventory produces incorrect when the records start off with a null inventory.Date Inv----------------10/1/200710/2/200710/3/2007 1010/4/2007 810/5/2007 10/6/2007 10/7/2007 10/8/2007 10/9/2007 6 It will not give me the correct results because there shouldn't be records for 10/1 and 10/2. |
 |
|
|
|
|
|