The snippet library.
Small, practical examples. Search by task or narrow things down below.
Accept either of two conditions
SQL Server: Use OR to keep matching names or out-of-stock rows.
SQL Server✓ Tested
Add values across several rows
SQL Server: Use SUM to calculate a total quantity.
SQL Server✓ Tested
Calculate a total for each group
SQL Server: Group nonmissing categories and calculate separate totals.
SQL Server✓ Tested
Calculate a value with SELECT
SQL Server: Evaluate a small arithmetic expression on the database server.
SQL Server✓ Tested
Count the rows in a table
SQL Server: COUNT(*) includes every row, including rows with NULL columns.
SQL Server✓ Tested
Create a table and insert its first row
SQL Server: Define column types and a primary key, then insert one row using an explicit column list.
SQL Server✓ Tested
Delete one row from a practice table
SQL Server: Restrict DELETE with a primary-key condition and verify the remaining row count.
SQL Server✓ Tested
Display a fallback for missing data
SQL Server: Return a supplied label when a column contains NULL.
SQL Server✓ Tested
Filter by a numeric comparison
SQL Server: Keep rows whose quantity exceeds a chosen threshold.
SQL Server✓ Tested
Filter groups after aggregation
SQL Server: Use HAVING to test a group’s calculated total.
SQL Server✓ Tested
Find missing values with IS NULL
SQL Server: Use IS NULL rather than equality to test for missing data.
SQL Server✓ Tested
Give a result column a readable name
SQL Server: Use AS to label a computed result column.
SQL Server✓ Tested