Have you ever wanted to get a running total of all of the descendants of each tree node? This sort of thing is useful, especially if you don’t want to pull back an entire object graph just to compute the count of a child collection.
IF OBJECT_ID(‘tempdb..#categories’) IS NOT NULL
DROP TABLE #categories;
IF OBJECT_ID(‘tempdb..#product_categories’) IS [...]
Businesses have all kind of interesting rules for working with data. Sometimes these rules are incredibly easy to implement in the database. Sometimes these rules are incredibly to implement in the application layer. Sometimes, it’s difficult to construct these rules no matter where you are in the entire application stack.
I recently came across a situation [...]
Before diving into how to go about using a common table expression, let’s take a look at what a common table expression is and why you would want to use one.
The What and Why of Common Table Expressions
Essentially, a common table expression (CTE) is a temporary result set. In this regard, a CTE is similar [...]