sql query not giving expected results in sql server -
i using sql server , table structure
start end interval 1 3 1 9 12 1 16 20 2 100 120 5
expected result
1 2 3 9 10 11 12 16 18 20 100 105 110 115 120
i tried before posting here
select start result,end1,interval table union select result+1,interval,end1,interval table
this perfect place use cte. following code should give answer you're looking for:
;with intervalcte ( select [start] value, [end], [interval] t union select [value] + [interval], [end], [interval] intervalcte [value] < [end] ) select value intervalcte order value
i've created sql fiddle can at.
Comments
Post a Comment