MCITP

MCITP

Wednesday, September 21, 2011

How to run a script file in SQL Server and get output direct into text file.

This is a method by which you can run any script file and get the output directly into text file.

1. Without using SSMS (SQL Server Management Studio)

sqlcmd -S Servername\InstanceName  -i C:\filename.sql -o C:\result.txt

e.g. Suppose file name is info.sql and servername is test (default instance)

a. Copy the file info.sql in C drive.
b. open the cmd shell and paste the command written below
    sqlcmd -S test  -i C:\info.sql -o C:\result.txt
c. Enter

See the ouptut of the query in the result.txt file created in C drive of the server.

2. Using SSMS

a. Copy the script in the new query.
b. Press CRTL+F
c. Press F5.

Get the result in text file.

No comments:

Post a Comment

Followers