Contents tagged with t-sql
-
TIL: You can use column aliases in an ORDER BY clause
This is almost certainly something a lot of other people know, but I've somehow managed to not learn it in the many (many!) years of using SQL Server that I have under my belt...
You can use the …
-
Using SQL Server to generate ranges and group data into them
One of the reporting requests I see from time to time is to have output grouped into ranges, or bands if you prefer, e.g:
From
To
Quantity
Value
0
250
3
125.52
250
500
8
3, …
-
Persuading a SQL Server UDF to throw
Unfortunately (and annoyingly, at times!) it's not possible to persuade a SQL Server User-Defined Function to throw, though I've managed to find (more by luck thank judgement!) a way to get the …
-
Using Common Table Expressions to explode recipes - Part 2 - Getting the ingredients
A Brief Recap
In the last part of this article I showed a table structure for recipes and their ingredients. There are two kinds of ingredients that a recipe can contain, raw ingredients (e.g. …
-
Using Common Table Expressions to explode recipes - Part 1 - The CTE
A lot of the examples that you see for using Common Table Expressions (CTEs) in SQL Server, particularly recursive ones use examples that are around user hierarchies - showing ways to find all the …
-
Using Sequence Numbers in SQL Server
Microsoft introduced the concept of Sequence Numbers in SQL Server 2012 which are:
... a user-defined schema-bound object that generates a sequence of numeric values according to the specification …