Repeating rows based on a value in a different column

I’ve just replied to a question in dotnethell italian forum about the topic in the title. Actually it’s not the first time I got this kind of question:

“How can I repeat a row using a value that is stored in another column of the same table?”

 
Ok, let’s describe a solution step by step.

SQL Server Logical Query Processing summary

Usually I found some questions on the forums about that topic. For instance:

  1. “WHERE or HAVING?”
  2. “Is the ON clause more efficient than the WHERE clause?”
  3. “Why the field aliases cannot be used with the GROUP BY clause?”
These three questions are syntax oriented. Actually there are a lot of requests about subqueries, temporary objects, sort operations and so on. This kind of questions can be replied reading this logical process document (pdf). I love it and I share it everywhere, also when training in classes/on the job.
It is a LOGICAL workflow used by the Query Processor in order to generate the related PHYSICAL process for retrieving data.