Itzik - You gave a simple to understand and excellent technical explanation of both approaches. My hat's off to you and thanks.
Excellent follow up piece.
I want to thank you for mentioning the solution I posted to Part I. But I also want to give some credit where credit is due.
I turned a friend of mine on...
Here's an improvement (I think):
SELECT @Rows = (SELECT COUNT(*) FROM @P);
DECLARE @VAL INT = (SELECT TOP 1 val FROM @P ORDER BY keycol) ;
WITH OnlyNeededRows AS
Get answers to questions, share tips, and engage with the SQL Server community in our Forums.
Sponsored Introduction Continue on to (or wait seconds) ×