Multiple aggregates in one query read a table once, where separate subqueries read it again and again. This post measures the logical reads of two subqueries against one SELECT, uses CASE inside SUM for different filters, and shows two cases where the rewrite gains nothing or loses to an index.
SQL Puzzle – IN and IS NOT NULL – Strange Results
Today, let us see a very simple puzzle where we are getting strange results when using NOT IN and IS NULL in a T-SQL query.
How to Force Index on a SQL Server Query? – Interview Question of the Week #281
Question: How to Force Index on a SQL Server Query?
Answer: I personally do not like to force an index on any query. Let us learn together.
Shaping Query Results as JSON With FOR JSON PATH
Shape FOR JSON PATH output with nested objects, child arrays, null options, and wrappers, then return one complete JSON value to clients.
Give Memory Back to the OS? Why SQL Server Doesn’t
This is a guest post by Brian Gale. It explains why SQL Server doesn’t give memory back to the OS, what the buffer pool keeps in that memory, and why max server memory needs a realistic value. Two queries show what is held right now.
ORDER BY a Parameter in SQL Server: CASE, Types and Plans
To ORDER BY a parameter in SQL Server, write one CASE expression for each column and direction. This post builds the procedure, shows the type conversion and DISTINCT errors that trip people up, measures the cost of the sort that CASE forces, and compares OPTION (RECOMPILE) and dynamic SQL.
How to Find IP Address of All SQL Server Connection? – Interview Question of the Week #280
Question: How to Find the IP Address of All SQL Server Connection?
I had recently received this question during a recent consultation.







