Microsoft SQL Server 2005

Version of implementation Microsoft SQL Server of programming language SQL

Microsoft SQL Server 2005 (codenamed Yukon) is the next after SQL Server 2000 version of Microsoft SQL Server. It features native support for XML processing, error handling and support for recursive queries, as well as numerous minor enhancements.

Examples:

Factorial - SQL (16):

This example uses recursive factorial definition, implemented as a recursive query — a feature included in SQL Server 2005 and higher. Each row of recursive query contains two numeric fields — n and f = n!, and each row is calculated using the data of the previous row.

with factorial(n, f) as
(
 select 0, 1
  union all
 select n+1, f*(n+1) from factorial where n<16
)
select cast(n as varchar)+'! = '+cast(f as varchar)
  from factorial

Fibonacci numbers - SQL (17):

This example uses a kind of iterative definition of Fibonacci numbers, implemented with a recursive query. Each row of recursive query contains two consecutive numbers of the sequence, and next row is calculated as (last number, sum of numbers) of previous row. This way most numbers are stored twice, so only first number of each row is included in the result.

with fibonacci(a, b) as
(
 select 1, 1
  union all
 select b, a+b from fibonacci where b < 1000
)
SELECT cast(a as varchar)+', ' AS [text()]
  FROM fibonacci
   FOR XML PATH ('')

Hello, World! - SQL (15):

select 'Hello, World!';