?
Solved

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

Posted on 2009-05-07
2
Medium Priority
?
592 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

765 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