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
