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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 adding fib

Author  Topic 

rohitdev2k12
Starting Member

3 Posts

Posted - 2014-11-25 : 01:40:00
id number
1 2
2 4
3 6
4 10

o/p should be
number
2
6
10
16


Ifor
Aged Yak Warrior

700 Posts

Posted - 2014-11-25 : 06:41:34
[code]
-- *** Test Data ***
CREATE TABLE #t
(
id int NOT NULL
,number int NOT NULL
);
INSERT INTO #t
SELECT 1, 2
UNION ALL SELECT 2, 4
UNION ALL SELECT 3, 6
UNION ALL SELECT 4, 10;
-- *** End Test Data ***

SELECT T1.number + COALESCE(T2.number, 0) AS Result
FROM #t T1
LEFT JOIN #t T2
ON T1.id = T2.id + 1;
[/code]
Go to Top of Page
   

- Advertisement -