How to "set echo on" in SQL Server 2005 to see code along with results?

  • Hello all! I am brand new to this forum, so my apologies in advance for any breach of etiquette. :blush:

    I have been using SQL Server 2005 for a few months now. In a previous life, I spent a lot of time with Oracle SQL. In Oracle, there is a command--SET ECHO ON. This is incredibly useful. When running a large batch of code, the actual lines being executed are shown on the screen before each result.

    So for example, instead of seeing just:

    (3648 row(s) affected)

    (14483 row(s) affected)

    You'd see the chunks of code displayed before each line. This is sort of a silly example, but if you had dozens and dozens of statements, you can see how it would be useful. Very useful indeed!

    Anyway, SET ECHO ON doesn’t work in SQL Server 2005. Is there anything that does?

    Thanks in advance for any help!

    Zack

    zrodman@rtcrm.com

  • In SSMS you can go to Tools -> Options -> Query Results and in the Results to Grids/Text there is an option to include the query in the result set.

  • Thanks so much! I wasn't aware that these options existed. This does help somewhat in that it shows the entire block of code prior to all the results. But it doesn't actually show the specific code just prior to the specific result. For example:

    Here are 3 UPDATE statements:

    Update TABLE set FIELD1 = 1;

    Update TABLE set FIELD2 = 2;

    Update TABLE set FIELD3 = 3;

    What I want to see is:

    Update TABLE set FIELD1 = 1;

    (500 row(s) affected)

    Update TABLE set FIELD2 = 2;

    (500 row(s) affected)

    Update TABLE set FIELD3 = 3;

    (500 row(s) affected)

    Setting this option gives me:

    /*------------------------

    Update TABLE set FIELD1 = 1;

    Update TABLE set FIELD2 = 2;

    Update TABLE set FIELD3 = 3;

    ------------------------*/

    (500 row(s) affected)

    (500 row(s) affected)

    (500 row(s) affected)

    Any other ideas? Is there anything that can be set within the code itself? Again, THANKS!

  • Sorry, there is nothing else I can think of.

  • AFAIK, there isn't a way to do this. You could print the query

    Update TABLE set FIELD1 = 1;

    print 'Update TABLE set FIELD1 = 1;'

    Update TABLE set FIELD2 = 2;

    print 'Update TABLE set FIELD2 = 2;'

    Update TABLE set FIELD3 = 3;

    print 'Update TABLE set FIELD3 = 3;'

  • This request may be and old one but I have found a solution to the query.

    Go to Query -> Query Options

    Select Text in the Results tree on the Opened windows

    Tick Include the query in the Result set

    Press OK

    Select Query ->Results to You may choose either Results to Text or Results to file.

    You will see your query, data output and final statement how-many rows effected on the same view

    Regards , Shaamil.

  • ok, thank you for sharing

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply