I\'ve started learning Prolog and wondering about the theoretical difference from the SQL language.
For example:
xonix, you need more development experience to say whether something can be done in sql or not.
Below are at least 2 solutions for your fibo series. One using Stored Procedure
and the other using CTE
. Take your pick.
METHOD 1
declare @a int, @b int, @c int, @i int, @N int = 10
select @a=0, @b=1, @i=0, @c=0
print @a
print @b
while @i < @N
Begin
set @c=@a+@b
print @c
set @i=@i+1
set @a=@b
set @b=@c
end
METHOD 2
WITH FibonacciNumbers (RecursionLevel, FibonacciNumber, NextNumber)
AS (
-- Anchor member definition
SELECT
0 AS RecursionLevel,
0 AS FibonacciNumber,
1 AS NextNumber
UNION ALL
-- Recursive member definition
SELECT a.RecursionLevel + 1 AS RecursionLevel,
a.NextNumber AS FibonacciNumber,
a.FibonacciNumber + a.NextNumber AS NextNumber
FROM FibonacciNumbers a
WHERE a.RecursionLevel < 10
)
-- Statement that executes the CTE
SELECT
'F' + CAST( fn.RecursionLevel AS VARCHAR) AS FibonacciOrdinal,
fn.FibonacciNumber,
fn.NextNumber
FROM FibonacciNumbers fn;
GO