Diagnose join duplicates before using DISTINCT, verify order and payment totals, and choose aggregation or EXISTS for the required result.
MONTH, DATEPART and DATENAME: Getting Month Names and Numbers Right
Use DATENAME for month labels, compare MONTH and DATEPART, control language and culture, and group sales without combining different years.
Makers That Sell PCs but Not Laptops: HAVING With Conditional Counts
One WHERE clause cannot say ‘has a PC but no laptop’. Here are three queries that can, and the NULL trap.
Finding the Most Frequent Value per Group in T-SQL
Find the most frequent value in each group, choose a tie policy, and compare categorical modes with averages and numeric percentiles.
Cohort Retention Tables in T-SQL: From Raw Events to a Grid
Build a retention grid from raw orders with five rows you can check by eye. Includes the DISTINCT rule and why unfinished months show NULL.
Subtotals and Grand Totals With ROLLUP and GROUPING SETS
Build region, product, and grand totals with ROLLUP, CUBE, and GROUPING SETS, then label subtotal rows and compare plans.
Effect of Collation on Result Sets in SQL Server
The effect of collation on result sets is easy to see once you run the same query against two collations. This post builds a small demo and shows how sorting, comparing and grouping change. It also explains collation conflicts, including the one temp tables cause.







