SQL: generate date/time series

There are many examples of user defined table functions generating the series of dates(times) between two specified values. Usually, in OLAP you can see a table filled by the date/time series, too. Such table avoid to generate the values "on the fly".

However, in some cases you may be unable to use an UDF or a table. Fortunately, "pure SQL" method still works.

Suppose, the start and finish dates are specified as entry parameters. The transact SQL code below generates the series "moth by month".

SQL quine (self-reproducing SQL)

A quine is a computer program which takes no input and produces a copy of its own source code as its only output. The challenge for programmers is to write the shortest code in the given language. Here are my examples in Transact SQL and in ANSI SQL.

Note that we do not take in account the output format printing by any console SQL clients. For example, we are unable to suppress the output of column names or separators in the common case.


Subscribe to RSS - SQL