Solved

How do I echo the query in my text output in SQL Server

Posted on 2009-05-07
2
590 Views
Last Modified: 2012-05-06
In Oracle, you can "Set echo on" and when you run a script the query and the output are output in the results.  I want to do the same in SQL Server.  I am unit testing in SQL Server and I want to see both the query and the results in the log file I attach to my unit test document.

Can someone help me?  I am using Microsoft SQL Server Management Studio for 2005.

Thank you.
0
Comment
Question by:BJTurner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
bljak earned 500 total points
ID: 24327474
If you are having your resultset displayed in TEXT or GRID, you can use shortcut Ctrl+Shift+O to get to Query Options, or alternatively Menu Query->Query Options.
There, expand Results and you will have "Grid" and "Text" for both, you can check the checkbox "Include the query in the resultset".

Tho, if your output is GRID, query will be in resultset window, in tab "Messages" and not under result.
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24327630
If you want to write both the query and result sets into a file, then follow the steps below:

1. Go to Query Menu --> Query Options and Check option Include the Query in Resultset.
2. Go to Query Menu --> Results to --> Results to File

http://blog.sqlauthority.com/2007/07/19/sql-server-2005-ssms-viewsend-query-results-to-textgridfiles/

Now your results will be written to a text or whatever file specified similar to spooling in Oracle.

Hope this helps.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question