How to output results onto a TEXT file?

How to output results onto a TEXT file?

Post by Ricky Cru » Fri, 27 Jun 2003 11:18:48



Hi,

I have a script:  myscript.sql

that contains a simple command: select * from mytable;

How can I modify the script to output the results onto a text file?  

For example: Oracle uses the command: SPOOL C:\OUTPUT.LOG

Is there a similar way for SQLServer?

I have tried using the BCP utility as follows:

bcp mydb.user1.mytable out c:\output.log -i myscript.sql  -S myserver -T

But the result is:
Invalid prefix length. Valid prefix-lengths are 0, 1, 2, or 4.
Try again:

So I am looking at an alternative way to initiate the output from my sql
script rather than from the bcp command utility.

I would appreciate your help.

Thanks in advance,
Ricky

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

How to output results onto a TEXT file?

Post by SriSam » Fri, 27 Jun 2003 11:29:56


You can use OSQL for this. Here is one sample command line:
osql -Spc-srinivas -Usa -Ppassword -i"test.sql" -o"C:\Temp\out.txt"

The "test.sql" file contains: SELECT * FROM pubs..authors
--
HTH,
SriSamp
Please reply to the whole group only!


Quote:> Hi,

> I have a script:  myscript.sql

> that contains a simple command: select * from mytable;

> How can I modify the script to output the results onto a text file?

> For example: Oracle uses the command: SPOOL C:\OUTPUT.LOG

> Is there a similar way for SQLServer?

> I have tried using the BCP utility as follows:

> bcp mydb.user1.mytable out c:\output.log -i myscript.sql  -S myserver -T

> But the result is:
> Invalid prefix length. Valid prefix-lengths are 0, 1, 2, or 4.
> Try again:

> So I am looking at an alternative way to initiate the output from my sql
> script rather than from the bcp command utility.

> I would appreciate your help.

> Thanks in advance,
> Ricky

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!


 
 
 

1. output query results to a text file

Hello all,
I am trying to write a sproc that I can schedule as a Scheduled Task in SQL
Server 6.5.   How can I save the output to a text file?

I know how to email the results of a query but can't for the life of me
figure out how to write out to a file.  I'm sure I am missing something very
basic and am hoping someone can point me in the right direction.

Many thanks,
Deb Joyce

2. Need user info from logs

3. Output result into text file

4. Pdox 7/NT objectpal -setrange/setgenfilter

5. Outputting results to a text file

6. Interbase indexes not working

7. Output Query Result to Text File with BCP

8. <None>

9. Output query result to a text file?

10. Output Query Results to Text File

11. Outputting results to a text file

12. result of SQL statements, should be output it to a text file

13. Oracle8i stored procedures - output result to text file