SQL到文本文件 [英] SQL to text file

查看:128
本文介绍了SQL到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个查询
从客户,发票中选择customer.customer_name,invoice.invoice_date,其中invoice.customer_id = customers.invoice_id和status =待处理"

我希望将此查询放到"C:\ Pending invoice.txt"上的文本文件中,并且它应该是自动的.意味着我不想手动将此结果保存到文本文件

谁能给我示例查询

感谢您阅读本文!

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!

推荐答案

以下内容应该为您工作:
The following should work for you:
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.


感谢您的帖子
我使用用户名和密码进行操作,但
问题仍然存在 无效的对象名称"
但是该查询可以在SQL 2000上运行,但是不知道为什么不能在SQL 2005上运行
可能是数据库的权限
我是那个用户sysadmin"sa"

任何人都可以解决这个问题

谢谢
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


您正在使用mysql吗?如果是这样,您所需要做的就是:

SELECT * FROM yourtable INTO OUTFILE``C:/asd.txt''
are you using mysql?? if so all you need to do is this :

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


这篇关于SQL到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆