Do not use on any
shared computer
August 30, 2008 04:43am pdt
 
[x]
Attachment Details

T-SQL fill rows with same date between dates

Tags: Microsoft, SQL Server, 2005
READ FIRST: I already have a date table, just call it "tblDates".  How do fill in the dates with the same data as the previous record unitl it changes?

I have events for employees in a table "EmpEvents":
EmpID   eDate          eEvent           eSch          eClass
100       1/1/2008    1                    51              11
100       1/3/2008    7                    32              50
100       1/15/2008  3                    88              8
100       1/20/2008  9                    23              43

I need it returned as follows using a stored procedure (THIS HAS TO BE DYNAMIC, NO ADDITIONAL TABLE UNLESS THEY ARE TEMP IN MEMORY).  Basically fill in the missing days with the same information as the previous record until it changes as follows:
EmpID   eDate          eEvent           eSch          eClass
100       1/1/2008    1                    51              11
100       1/2/2008    1                    51              11
100       1/3/2008    7                    32              50
100       1/4/2008    7                    32              50
100       1/5/2008    7                    32              50
100       1/6/2008    7                    32              50
100       1/7/2008    7                    32              50
100       1/8/2008    7                    32              50
100       1/9/2008    7                    32              50
100       1/10/2008  7                    32              50
100       1/11/2008  7                    32              50
100       1/12/2008  7                    32              50
100       1/13/2008  7                    32              50
100       1/14/2008  7                    32              50
100       1/15/2008  3                    88              8
100       1/16/2008  3                    88              8
100       1/17/2008  3                    88              8
100       1/18/2008  3                    88              8
100       1/19/2008  3                    88              8
100       1/20/2008  9                    23              43
100       1/21/2008  9                    23              43
100       1/22/2008  9                    23              43
and so on...
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Microsoft
Question Asked By: ascnd
Solution Provided By: momi_sabag
Participating Experts: 2
Solution Grade: A
Views: 43
Translate:
Loading Advertisement...
 
[+][-]Accepted Solution by momi_sabag

Rank: Guru

Accepted Solution by momi_sabag:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by ascnd
Author Comment by ascnd:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Open Discussion
Open Discussion
 
Comment by carlink
Hi. I have the same problem and the solution for momi_sabag is great and i solve my problem in part.
see:
id      date      mount
17      01/01/2005      100
17      01/02/2005      100
17      01/03/2005      100
17      01/04/2005      100
17      01/05/2005      100
17      01/06/2005      100
17      01/07/2005      100
17      01/08/2005      100
17      01/09/2005      100
17      01/10/2005      100
17      01/11/2005      100
17      01/12/2005      100
17      01/01/2006      100
17      01/02/2006      100
17      01/03/2006      100
17      01/04/2006      100
17      01/05/2006      100
17      01/06/2006      900
I need fill in the missing next (months) to current date with the same information as the previous record until it changes as follows:
id      date      mount
17      01/06/2006      900
17      01/07/2006      900
17      01/08/2006      900
17      01/09/2006      900
17      01/10/2006      900
17      01/11/2006      900
17      01/12/2006      900
17      01/01/2007      900
17      01/02/2007      900
17      01/03/2007      900
17      01/04/2007      900
17      01/05/2007      900
17      01/06/2007      900
17      01/07/2007      900
17      01/08/2007      900
17      01/09/2007      900
17      01/10/2007      900
17      01/11/2007      900
17      01/12/2007      900
17      01/01/2008      900
17      01/02/2008      900
17      01/03/2008      900
17      01/04/2008      900
17      01/05/2008      900
Please i need help you
PD. I modify the script for months (DATEADD(MM,1,@ID_FEC)), DATEADD(MM,-1,@ID_FEC)
 
 
20080723-EE-VQP-34 / EE_QW_2_20070628