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 owing to the 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".