Collection of methods to generate random string in a single SQL statement
M1: Recursive string concatenation
On SQL Server the method is limited by 100 characters because of CTE recursion level limitation. The method has the performance issues when using in loops/joins because the table always have 100 rows generated every time.
Better to see once than to hear a hundred times. This small article explains what are the different kinds of joins in SQL.
At the first time you should take into account that SQL is a declarative 4th generation language. So the best way to use it (especially for beginners) is to write the query and let SQL optimizer do its job. That means thinking in set-oriented terms and avoiding sub-queries.
Let's take two example tables: Companies and Contacts.
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".
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.