Matching Supply With Demand — Solutions, Part 1
Last month, I covered Peter Larsson's puzzle of matching supply with demand. I showed Peter's straightforward cursor-based solution and explained that it has linear scaling. The challenge I left you...
View ArticleMatching Supply With Demand — Solutions, Part 2
[ Jump to: Original challenge | Solutions: Part 1 | Part 2 | Part 3 ] In this article, I continue the coverage of solutions to Peter Larsson’s enticing matching supply with demand challenge. Thanks...
View ArticleString Aggregation Over the Years in SQL Server
Since SQL Server 2005, the trick of using FOR XML PATH to denormalize strings and combine them into a single (usually comma-separated) list has been very popular. In SQL Server 2017, however,...
View ArticleMatching Supply With Demand — Solutions, Part 3
[ Jump to: Original challenge | Solutions: Part 1 | Part 2 | Part 3 ] In this article, I continue exploring solutions to the matching supply with demand challenge. Thanks to Luca, Kamil Kosno, Daniel...
View ArticleIslands T-SQL Challenge
Recently, I was introduced to a new islands challenge by my friend Erland Sommarskog. It’s based on a question from a public database forum. The challenge itself isn’t complicated to handle when using...
View ArticleAre You Sorted? Tips Concerning T-SQL Window Ordering
A supporting index can potentially help avoid the need for explicit sorting in the query plan when optimizing T-SQL queries involving window functions. By a supporting index, I mean one with the window...
View ArticleT-SQL Windowing Improvements in SQL Server 2022
Microsoft recently released the first public preview of SQL Server 2022. This release has a number of T-SQL improvements. In this article I focus on windowing and NULL-related improvements. These...
View ArticleT-SQL Can Be Expressive Without Sacrificing Performance
Even with its warts and limitations, Transact-SQL is a beautiful language, allowing for flexible declarative expression about what you’re asking the database engine to do for you. Itzik Ben-Gan has...
View ArticleEmulating the GROUPS Window Frame Option
Generally in life, it’s good to have the perfect tools to handle any given task. But sometimes a tool you need isn’t available, and you have to figure out a solution without it. The same goes...
View ArticleDATE_BUCKET and DATETRUNC Improve Optimization of Time-Based Grouping
Time-based grouping and aggregation are common in analyzing data using T-SQL—for example, grouping sales orders by year or by week and computing order counts per group. When you apply time-based...
View Article