Solved

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

Posted on 2009-05-07
2
586 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
CAST issue with SQL 2000 15 42
Help with SQL pivot 11 47
SQL 2008 - Disappearing Temp Table in Stored Procedure 24 58
SQL - Load records to temp table through CTE 6 36
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

737 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