Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I spool the output of a query to a file in SQL Server

Posted on 2011-02-24
2
Medium Priority
?
5,179 Views
Last Modified: 2013-11-05
Is there an equivalent to Oracle’s “spool” function on SQL Server? I need the output of a query spool to a file. The query will be run as a cron job as a schedule task, any suggestions?    
0
Comment
Question by:dbawant2b
[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:
MarioAlcaide earned 2000 total points
ID: 34970828
We have many options.  Here are just a few that I think can help solve your problem...

SQL Server 2000:
OSQL/ISQL - SQL Server 2000 command line tools.
SQL DMO - Management API
T-SQL

SQL Server 2005:
SQLCMD - Command line tool
SQL SMO - Management API (really easy to script in .NET)
Generate Script Wizard (You choose the objects in your database that you want to script and the settings.  It generates the scripts for you.) (In SQL Server 2005 SP2, you can generate DROP statements for objects and script each object to its own file.)


If you want to save the results from this T-SQL script to a file, you can:

1) Have Management Studio save it to a file:
Query | Results To | Results to File or Shortcut Key (CTRL + SHIFT + F)

2) Use SQLCMD to output the results to a file:
a) Save the T-SQL query above to a .sql file
b) Use the -e option to echo your input file into your output file
SQLCMD -i Input.sql -o C:\Results.txt -e

0
 

Author Closing Comment

by:dbawant2b
ID: 34972156
Thanks for your help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 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