Link to home
Start Free TrialLog in
Avatar of abrusko
abruskoFlag for United States of America

asked on

How do I "spool" query output to a txt file?

Hi, can someone please tell how I would "spool" the results of a select statement to a text file for future processing?

I'm a little unclear (I'm familiar with Oracle/SQL*Plus) on how I would run a query directly on the server as well, so if someone could tell me how I go about running a query on the server AND how I can have the results of that query "spool" to a .TXT file, I would be much obliged.

Thanks alot!
Andy
Avatar of nigelrivett
nigelrivett

You could use "bcp" with the queryout option, not quite like a SPOOL in PL/SQL but close enough. BCP will not put the column headers, that's all. For example, your query is "SELECT * FROM DB1.dbo.TABLE1" on server SERVER, you could do --
bcp "SELECT * FROM DB1.dbo.TABLE1" queryout Table1Select.txt -SSERVER -Usa -P -c
in the simplest format (you can define your field and row terminators with -t and -r options, default for -t is tab and -r is newline). Substitute -Usa -P with the appropriate UserID and Password. HTH.
ASKER CERTIFIED SOLUTION
Avatar of miron
miron
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abrusko

ASKER

miron...thanks...we ended up using OSQL

jchopde...thanks for your help too, but the OSQL solution was best for us...thanks again to both of you...I appreciate it!