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.

Differences between SSMS and query execution time

Sometimes, in the forums I’m following, I face some questions about different execution times between Sql Server Management Studio and executions.

Questions like “Why my SSMS queries run so fast and my queries are so slow?”. This is a scaring behavior that you can verify lots of times. Some application’s logs tell to us a too large timing. When you copy/paste the SQLCommand into a new query window using SSMS (also on the incriminated server) the execution time is very short.

Continue reading “Differences between SSMS and query execution time”

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.