Producing the below result

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 310
DECLARE @tab TABLE(AnswerDelay int, DelayTime int)
insert into @tab
SELECT 2, 1 union all
SELECT 4, 5 union all
SELECT 6, 6 union all
SELECT 8,28 union all
SELECT 10, 27 union all
SELECT 12, 12 union all
SELECT 14, 20 union all
SELECT 16, 25
/*
There are some scenarios to produce this type of results....
Based on AnswerDelay column, produce the results.....

if the AnswerDelay column have data as 2, 2 records; if it has 4 then 4 records; if 6 then 6 records ans so on...

AnswerDelay
2
2
4
4
4
4
6
6
6
6
6
6*/


;With DelayTimes
AS
(
SELECT AnswerDelay,CAST(1 AS int) AS Counter,DelayTime
FROM @tab
UNION ALL
SELECT AnswerDelay,Counter+1,DelayTime
FROM DelayTimes
WHERE Counter+1<= DelayTime
)
SELECT AnswerDelay
FROM DelayTimes
ORDER BY AnswerDelay
OPTION (MAXRECURSION 0)

Comments or Responses

Login to post response