Solved

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

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Upgrading my SSIS package in VS 2012 6 62
Amazon RDS migrate to SQL Server 3 26
Query for timesheet application 3 20
Setting variables in a stored procedure 5 23
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

830 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