Building a string of values in T-SQL

It is often far too easy to experience some behaviour in SQL Server, and then extrapolate your belief from that. One example that is seen frequently on forums is the simplistic case of concatenating values into a scalar variable, however the logic that is commonly assumed is false. Take the example USE tempdbGOIF OBJECT_ID(‘CharsTable’,’U’) IS Read more about Building a string of values in T-SQL[…]

Helping the Query Optimizer with Constraints

The Query Optimizer in SQL Server is an amazing piece of code. It takes any query we choose to throw at it, evaluates many different ways of executing that query and, generally speaking, comes up with an execution plan that is going to be good enough. And it does all that in milliseconds. Sometimes it Read more about Helping the Query Optimizer with Constraints[…]

Power and Deception of CTEs

This is a reprint of an article of mine that appeared on in December 2008 Introduction A customer of mine had a performance problem with a stored procedure that uses Common Table Expressions (CTEs). The performance had gone from sub second to 10-12 secs, and the approach that was being taken to diagnose and Read more about Power and Deception of CTEs[…]