Wednesday, March 7, 2012

How can I write results of a query to output file and save it to the disk

Hi All,
Is there a way to write the results of a query to a file and save it to the
disk? I know that the SQL Query Analyzer gives us the option of 'results to
file'. I want to know whether I can write a script which can query the
database and redirect the results to a file, so that I can open the script
file thru SQL Query Analyzer and run it or even I can use this script in Job
Scheduling when I want.
Thanks,
NN> Is there a way to write the results of a query to a file and save it to
the
> disk? I know that the SQL Query Analyzer gives us the option of 'results
to
> file'. I want to know whether I can write a script which can query the
> database and redirect the results to a file, so that I can open the script
> file thru SQL Query Analyzer and run it or even I can use this script in
Job
> Scheduling when I want.
Just create a regular script, only T-SQL commands; you can run this commands
in QA, job task, or with OSQL.EXE command prompt utility. OSQL can save the
results to an output file. Check the parameters (specifically -i and -o) for
osql in Books onLine.
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com|||Q: How can I read/write to a flat file from inside a SQL Server TSQL
script/stored-procedure/trigger?
A: http://www.mssqlserver.com/faq/general-flatfile.asp
HTH, Jens Smeyer.
http://www.sqlserver2005.de
--
"Nagaraju Nookala" <iranichai@.netscape.net> schrieb im Newsbeitrag
news:OU6DYFFRFHA.3296@.TK2MSFTNGP15.phx.gbl...
> Hi All,
> Is there a way to write the results of a query to a file and save it to
> the disk? I know that the SQL Query Analyzer gives us the option of
> 'results to file'. I want to know whether I can write a script which can
> query the database and redirect the results to a file, so that I can open
> the script file thru SQL Query Analyzer and run it or even I can use this
> script in Job Scheduling when I want.
> Thanks,
> NN
>

No comments:

Post a Comment