Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a query
select customers.customer_name,invoice.invoice_date from customers,invoice where invoice.customer_id=customers.invoice_id and status='Pending'

I want this query out put to text file on 'C:\Pending invoice.txt' and it should be automatically. Means i do't want to manually save this result to text file

Can any body give me example query

Thanks for reading this!
Posted
Updated 6-Feb-10 8:18am
v2

The following should work for you:
SQL
DECLARE @FileName varchar(50)
SET @FileName = 'C:\Pending invoice.txt'
EXEC master..xp_cmdshell 'bcp "select customers.customer_name,invoice.invoice_date from 
customers,invoice where invoice.customer_id=customers.invoice_id and status='Pending'
" queryout "' + @FileName + '" -U ... -P ... -c'
Replace ... with the user/password combo that you need.
 
Share this answer
 
Thanks for your post
I do that with username and password but problem still there for
"Invalid object name"
But that query works on SQL 2000 but don't know why not working with SQL 2005
May be premission for database
I am user sysadmin "sa" for that

Can any body solve this

Thanks
 
Share this answer
 
are you using mysql?? if so all you need to do is this :

SELECT * FROM yourtable INTO OUTFILE 'C:/asd.txt'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900