The snippet library.
Small, practical examples. Search by task or narrow things down below.
Normalize ASCII text to uppercase
SQL Server: UPPER changes character case under the database’s text rules.
SQL Server✓ Tested
Page an ordered result
Skip rows and fetch a bounded page.
OFFSET✓ Tested
Pair employees with their managers
SQL Server: Alias a table twice to represent two different roles in one relationship.
SQL Server✓ Tested
Place missing values after known values portably
SQL Server: A CASE sort key controls NULL placement without relying on engine-specific defaults.
SQL Server✓ Tested
Rank tied scores with competition gaps
SQL Server: RANK leaves a gap after tied rows, unlike DENSE_RANK.
SQL Server✓ Tested
Rank tied scores without gaps
SQL Server: DENSE_RANK assigns equal ranks to ties and increments by one for the next distinct score.
SQL Server✓ Tested
Read a page after a known unique key
SQL Server: A keyset predicate avoids scanning and discarding an increasing offset on a suitable index.
SQL Server✓ Tested
Read a scalar JSON property
Extract a named value using a JSON path.
JSON_VALUE✓ Tested
Read named columns from a table
SQL Server: Choose the columns needed and request a deterministic row order.
SQL Server✓ Tested
Read the last value of the complete partition
SQL Server: Specify an unbounded-following frame so LAST_VALUE does not stop at the current row.
SQL Server✓ Tested
Read the next row’s value
SQL Server: LEAD reads a later ordered row without a self join and supports a fallback at the end.
SQL Server✓ Tested
Read the smallest and largest values
SQL Server: Use MIN and MAX without sorting and fetching every row.
SQL Server✓ Tested