liveBook · Manning

Immediate window

As explained in 100 SQL Server Mistakes and How to Avoid Them

The Immediate window is a debugger console for evaluating expressions or queries in the current execution context.

The Immediate window is a debugger console for running queries while execution is paused or without pausing, helping inspect the current execution context. Use it to test assumptions before changing a stored procedure. section 7.3

Mistake: trusting a multi-row assignment

A stored procedure produced a divide-by-zero error because @AvgCPM was zero. Running SELECT COUNT(*) FROM reporting.ImpressionAggregates WHERE CampaignID = @CampaignID in the Immediate window returned 42, revealing that the query returned many rows instead of one. Correct the procedure by aggregating the values and using compatible data types. section 7.3

Listing 7.15 Running a query in the Immediate window
SELECT COUNT(*) FROM reporting.ImpressionAggregates WHERE CampaignID = 
@CampaignID

Run the diagnostic count query to test whether the stored procedure's campaign lookup returns the single row its variable assignment expects. section 7.3

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Demonstrates diagnostic querying and notes limits on result sets and execution-environment-dependent functionality.
Examples
Uses a campaign summary procedure, a divide-by-zero error, and a count query returning 42 rows.
What it assumes
Assumes familiarity with SQL queries, variables, stored procedures, and debugger execution states.
What you can do after
Diagnose/debug with it by testing queries and exposing unexpected row counts during procedure execution.
How it connects
Connects debugging with stored procedures, breakpoints, the Locals window, query results, and data types.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.