Nested window functions in SQL
The ISO/IEC 9075:2016 standard (SQL:2016) defines a feature called nested window functions. This feature allows you to nest two kinds of window functions as an argument of a window aggregate function....
View ArticleT-SQL bugs, pitfalls, and best practices – window functions
This article is the fourth installment in a series about T-SQL bugs, pitfalls and best practices. Previously I covered determinism, subqueries and joins. The focus of this month's article is bugs,...
View ArticleT-SQL bugs, pitfalls, and best practices – pivoting and unpivoting
This article is the fifth part in a series about T-SQL bugs, pitfalls and best practices. Previously I covered determinism, subqueries, joins, and windowing. This month, I cover pivoting and...
View ArticleOverlooked T-SQL Gems
My good friend Aaron Bertrand inspired me to write this article. He reminded me of how sometimes we take things for granted when they seem obvious to us and don't always bother checking the full story...
View ArticleAnalyzing "death by a thousand cuts" workloads
There are multiple methods to look at poorly performing queries in SQL Server, notably Query Store, Extended Events, and dynamic management views (DMVs). Each option has pros and cons. Extended Events...
View ArticleRow numbers with nondeterministic order
The ROW_NUMBER window function has numerous practical applications, well beyond just the obvious ranking needs. Most of the time, when you compute row numbers, you need to compute them based on some...
View ArticleFiltered Indexes and Forced Parameterization (redux)
After blogging about how filtered indexes could be more powerful, and more recently about how they can be rendered useless by forced parameterization, I'm revisiting the filtered...
View ArticleNULL complexities – Part 1
NULL handling is one of the trickier aspects of data modeling and data manipulation with SQL. Let's start with the fact that an attempt to explain exactly what a NULL is is not trivial in and of...
View ArticleNULL Complexities – Part 2
This article is the second in a series on NULL complexities. Last month I introduced the NULL as SQL's marker for any kind of missing value. I explained that SQL doesn't provide you with the ability to...
View ArticleStrongly Type Those Table-Valued Parameters
Table-valued parameters have been around since SQL Server 2008 and provide a useful mechanism for sending multiple rows of data to SQL Server, brought together as a single parameterized call. Any rows...
View ArticleNULL complexities – Part 3, Missing standard features and T-SQL alternatives
This article is the third installment in a series on NULL complexities. In Part 1 I covered the meaning of the NULL marker and how it behaves in comparisons. In Part 2 I described the NULL treatment...
View ArticleNULL complexities – Part 4, Missing standard unique constraint
This article is Part 4 in a series about NULL complexities. In the previous articles (Part 1, Part 2, and Part 3), I covered the meaning of the NULL as a marker for a missing value, how NULLs behave in...
View ArticlePlease help with STRING_SPLIT improvements
We're mid-cycle between releases, where we're not yet hearing about any of the features planned for SQL Server vNext. This is probably the best time to press Microsoft for improvements, as long as we...
View ArticleFundamentals of table expressions, Part 1
This article is the first in a series about the fundamentals of table expressions in T-SQL. I will mainly focus on four types of named table expressions, which are known in T-SQL as derived tables,...
View ArticleVisualizing the Tipping Point with Plan Explorer
The tipping point is a term I first heard used by SQL Server performance tuning guru and long-time SentryOne Advisory Board member Kimberly Tripp – she has a great blog series on it here. The tipping...
View ArticleFundamentals of table expressions, Part 2 – Derived tables, logical...
Last month I provided a background to table expressions in T-SQL. I explained the context from relational theory and the SQL standard. I explained how a table in SQL is an attempt to represent a...
View ArticleFundamentals of table expressions, Part 3 – Derived tables, optimization...
In Part 1 and Part 2 of this series, I covered the logical, or conceptual, aspects of named table expressions in general, and derived tables specifically. This month and the next I’m going to cover the...
View ArticleFundamentals of table expressions, Part 4 – Derived tables, optimization...
This article is the fourth part in a series on table expressions. In Part 1 and Part 2 I covered the conceptual treatment of derived tables. In Part 3 I started covering optimization considerations of...
View ArticleFundamentals of table expressions, Part 5 – CTEs, logical considerations
This article is the fifth part in a series about table expressions. In Part 1 I provided the background to table expressions. In Part 2, Part 3, and Part 4, I covered both the logical and the...
View ArticlePlease stop using this UPSERT anti-pattern
ul.f { margin-bottom:0px!important; } I think everyone already knows my opinions about MERGE and why I stay away from it. But here's another (anti-)pattern I see all over the place when people want to...
View Article