I set some variables that are calculated dates and want to see a check of those as soon as a long-running query is started.
If I have an initial SELECT that displays the variables, it doesn't display until the query completes. And of course, if I insert a GO command I lose the variable values.
I want the initial SELECT to execute (display) right away.
The only work-around I can think of (as a sql beginner) is to write my variables into a temp table, use GO, and then read them back out. I hope there's a more elegant method. Is there?
(main query displays all at once, not piecemeal, due to a sort on a calculated column)
DECLARE @variable varchar(20)
SET @variable = '"SEARCH CRITERIA"'
SELECT 'Starting a query based on the criteria of: ' + @variable + '. This may take a while.' AS 'Intro that allows double check of criteria. ______________________________________'
WAITFOR DELAY '00:00:05.000' --just to simulate the time required to run the query. Often 10 minutes or more.
SELECT 'This is a long running query based on ' + @variable + '.' AS 'Main Query ________________________________________'