Advanced T-SQL: Replacing Slow Cursors with Window Functions
This article looks at replacing a cursor with a window function to improve performance.
2026-08-03
7,199 reads
This article looks at replacing a cursor with a window function to improve performance.
2026-08-03
7,199 reads
Introduction When developers first learn SQL aggregation, they usually start with the GROUP BY clause. It works well for summary reports because it combines multiple rows into a single result for each group. For example, you can calculate total sales per region or average salary per department. The limitation of GROUP BY appears when you […]
2026-06-05
4,750 reads
SQL Server 2022 brought powerful new T-SQL functions that eliminate long-standing workarounds. This article walks through five of the most impactful additions — GENERATE_SERIES, GREATEST/LEAST, DATE_BUCKET, the WINDOW clause, and IS NOT DISTINCT FROM — with practical code examples you can use immediately.
2026-05-29
7,405 reads
2026-05-22
599 reads
I’ve used SQL window functions for years, but I’ve never fully understood framing. To truly master window functions, you need at least a basic grasp of framing and how to apply it to your queries. Framing is especially helpful when working with aggregate functions. How can you overcome this hesitation to try framing?
2025-12-26
A look at window functions in SQL and how they can be used to query data without the restrictions of a GROUP BY.
2025-09-12
7,425 reads
2025-02-26
518 reads
2025-02-12
597 reads
2024-10-30
533 reads
2024-10-23
488 reads
By James Serra
(This is the third post in a three-part series on how AI is changing...
Continuing with my takeaways from SQLCon and FabCon Europe in Barcelona, let’s talk about...
By Steve Jones
Next year the PASS Data Community Summit is in DENVER! and London, but Denver...
Comments posted to this topic are about the item Pay for Performance, which is...
I wrote about this several years ago but will contribute again a life hack...
Hi I have this query that is slow during the 'not in' part of...
I run this query:
SELECT s.name AS schemaname , o.name AS objectname FROM sys.objects o INNER JOIN sys.schemas s ON s.schema_id = o.schema_id WHERE o.name = 'Beer'I get one row back for an object named dbo.beer. There is an ETL schema and both of these are nonpartitioned tables. I run this code:
ALTER TABLE dbo.beer switch TO etl.beerWhat happens? See possible answers