Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now