Hello, I am using IBM DB2, I have a table which gives me following data:
I want the output as:
I want one extra date column which gives me date from the start and end date.
The StartDate and EndDate column are of "date" datatype.Plz help!! I m using IBM DB2.
asked Aug 09, 2011 at 01:36 AM in Default
Whilst @Håkan Winther is right in that this is a MS-SQL Server site, maybe we can still point you in the right direction for the solution.
What you need to do is expand the days between start and finish. This can be done using a numbers or tally table.
I have managed this through the use of a common table expression (the code starting with "WITH"). This just generates a list of integers, starting with 0. I then multiply the original data using the inner join, driving the join by calculating the difference in days between the start and end of leave entry.
In your example the leave is 3 days, so three rows are generated. I then create a final column that turns the row number into the actual date that the row represents.
Take a look at the code, I have no idea how it would translate to DB2, but I think the general idea should be translatable.
INNER JOIN nums ON nums.n <= DATEDIFF(day, tt.START_DATE, tt.END_DATE)
answered Aug 09, 2011 at 02:01 AM