Home All Groups Group Topic Archive Search About

Query Analyser - output SQL commands to Results pane

Author
31 Oct 2006 10:38 PM
Johnny Williams
With Query Analyser for SQL Server 2000, when I open a .SQL script and
execute it, the 'Messages' tab of the Results pane contains the results of
executing the script, including any errors.  How do configure QA or
otherwise (e.g. by a command in the script), so that the each SQL command is
also output to the Results pane before the result of that command?

This would make it far easier to see debug scripts and determine immediately
which statement caused an error.

Thanks for any help.

Author
31 Oct 2006 10:45 PM
Arnie Rowland
As far as I am aware, there is no such capability.

You could copy the SQL command and put it in a Print statement just before
the execution.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous

You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf


Show quote
"Johnny Williams" <REMOVEjohnwilliams_***@NOThotmail.com> wrote in message
news:ei8j8c$8tk$1@news.freedom2surf.net...
> With Query Analyser for SQL Server 2000, when I open a .SQL script and
> execute it, the 'Messages' tab of the Results pane contains the results of
> executing the script, including any errors.  How do configure QA or
> otherwise (e.g. by a command in the script), so that the each SQL command
> is also output to the Results pane before the result of that command?
>
> This would make it far easier to see debug scripts and determine
> immediately which statement caused an error.
>
> Thanks for any help.
>
Author
31 Oct 2006 10:58 PM
Johnny Williams
OK, thanks.  How do people debug SQL scripts then?  Is there any sort of
debugger tool which can step through a script one statement at a time and
see the results of that statement?

thanks, JW

Show quote
"Arnie Rowland" <ar***@1568.com> wrote in message
news:utJg54T$GHA.4704@TK2MSFTNGP04.phx.gbl...
> As far as I am aware, there is no such capability.
>
> You could copy the SQL command and put it in a Print statement just before
> the execution.
>
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
>
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
> You can't help someone get up a hill without getting a little closer to
> the top yourself.
> - H. Norman Schwarzkopf
>
>
> "Johnny Williams" <REMOVEjohnwilliams_***@NOThotmail.com> wrote in message
> news:ei8j8c$8tk$1@news.freedom2surf.net...
>> With Query Analyser for SQL Server 2000, when I open a .SQL script and
>> execute it, the 'Messages' tab of the Results pane contains the results
>> of executing the script, including any errors.  How do configure QA or
>> otherwise (e.g. by a command in the script), so that the each SQL command
>> is also output to the Results pane before the result of that command?
>>
>> This would make it far easier to see debug scripts and determine
>> immediately which statement caused an error.
>>
>> Thanks for any help.
>>
>
>
Author
1 Nov 2006 9:10 PM
Aaron Bertrand [SQL Server MVP]
> OK, thanks.  How do people debug SQL scripts then?

I typically use PRINT statements.

I found too many issues and too much overhead/hassle using Query Analyzer's
debugger, and just don't have it in my list of top 10 things to do during
development.

A
Author
2 Nov 2006 10:57 PM
Erland Sommarskog
Johnny Williams (REMOVEjohnwilliams_***@NOThotmail.com) writes:
> OK, thanks.  How do people debug SQL scripts then?  Is there any sort of
> debugger tool which can step through a script one statement at a time and
> see the results of that statement?

You can wrap it in a stored procedure, and then use the T-SQL debugger.
But unless you are running QA on the same machine on the server, it
can be very difficult to get it to work, because there is a lot of
red tape with firewalls, permissions etc to get it to work.

Personally, I go the same road as Aaron: I use PRINT statments, or if
there is a lot, select to a debug table.

--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
2 Nov 2006 11:03 PM
Aaron Bertrand [SQL Server MVP]
> Personally, I go the same road as Aaron: I use PRINT statments, or if
> there is a lot, select to a debug table.

Yes!  Though I use this more for performance testing (e.g. when a stored
procedure is taking 5 minutes, and I want to find out which step(s) take
longest.
Author
2 Nov 2006 11:03 PM
Aaron Bertrand [SQL Server MVP]
> Personally, I go the same road as Aaron: I use PRINT statments, or if
> there is a lot, select to a debug table.

Yes!  Though I use this more for performance testing (e.g. when a stored
procedure is taking 5 minutes, and I want to find out which step(s) take
longest.
Author
31 Oct 2006 10:46 PM
Johnny Williams
Ha! Found it.

Tools - Options - Results - tick 'Output query'

If a .SQL script is run from the command line (not using osql etc. but
another 3rd party tool), what SQL command do I put in the script to tell it
to echo/log the commands?

thanks.

Show quote
"Johnny Williams" <REMOVEjohnwilliams_***@NOThotmail.com> wrote in message
news:ei8j8c$8tk$1@news.freedom2surf.net...
> With Query Analyser for SQL Server 2000, when I open a .SQL script and
> execute it, the 'Messages' tab of the Results pane contains the results of
> executing the script, including any errors.  How do configure QA or
> otherwise (e.g. by a command in the script), so that the each SQL command
> is also output to the Results pane before the result of that command?
>
> This would make it far easier to see debug scripts and determine
> immediately which statement caused an error.
>
> Thanks for any help.
>
Author
31 Oct 2006 10:54 PM
Johnny Williams
Scrap that, I was mistaken.  It only seems to echo the start of the script
to the Results pane, not all the SQL commands.

Show quote
"Johnny Williams" <REMOVEjohnwilliams_***@NOThotmail.com> wrote in message
news:ei8jog$997$1@news.freedom2surf.net...
> Ha! Found it.
>
> Tools - Options - Results - tick 'Output query'
Author
1 Nov 2006 9:28 AM
Dejan Sarka
> If a .SQL script is run from the command line (not using osql etc. but
> another 3rd party tool), what SQL command do I put in the script to tell
> it to echo/log the commands?

There is no such T-SQL command; therefore, it depends on the tool. Osql.exe,
which you mentioned, can echo the input. For other tools, is they do not
have built-in such feature, you can trace the commands with SQL Profiler.


AddThis Social Bookmark Button