Date

A new way to generate a list of numbers between 0 and 9999 in SQL Server 2008 using derived tables:

select thousands.digit + hundreds.digit + tens.digit + ones.digit as number
from ( select * from ( values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9') ) as t(digit) ) ones
join ( select * from ( values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9') ) as t(digit) ) tens on 1=1
join ( select * from ( values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9') ) as t(digit) ) hundreds on 1=1
join ( select * from ( values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9') ) as t(digit) ) thousands on 1=1