Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Txt file

Status
Not open for further replies.

gust1480

Programmer
Mar 19, 2002
148
PH
Can somebody pls help me how to make a query wherein the result should be in a txt file? I need the sql script on this. Tnx!
 

Only way I can see to do it would be to create a DTS package that runs the query creates a temp table with the results in and then exports the data to a text file for you.



I love deadlines. I like the whooshing sound they make as they fly by
Douglas Adams
(1952-2001)
 
one way is to use BCP

run this
exec master..xp_cmdshell 'bcp "SELECT au_fname, au_lname FROM pubs..authors ORDER BY au_lname" queryout c:\bcptest.txt -c -t ,'


this will create a text file on your C drive named bcptest.txt, the output is delimited by a comma

Denis The SQL Menace
SQL blog:
Personal Blog:
 

Denis

Thanx I've never used BCP so I'll have a look into it and see if I cna make us eof it on other things.



I love deadlines. I like the whooshing sound they make as they fly by
Douglas Adams
(1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top