SQL xp_cmdshell [英] SQL xp_cmdshell

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

问题描述


我有一个SQL我希望这个将输出保存到文本文件

但是不知道出了什么问题

我生成错误那个无效的对象名称payroll..employee_v



但是当我执行select语句时它工作文件

当我输入此命令时,这个SQL也可以正常工作

SELECT * FROM pubs..authors

请帮助谢谢



Hi I have a SQL i want this to save the output to text file
But don't know what is getting wrong
I generate error that "Invalid object name payroll..employee_v"

But when i execute the select statement it work file
And this SQL also work fine when i put this command
SELECT * FROM pubs..authors
Please help thanks

DECLARE @FileName varchar(50),
        @bcpCommand varchar(2000)

SET @FileName = 'C:\result.txt'

SET @bcpCommand = 'bcp "SELECT * FROM payroll..employee_v ORDER BY emp_no" queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -U sa -P 123 -c'

EXEC master..xp_cmdshell @bcpCommand

推荐答案

如果你试图运行这个会发生什么SQL窗口中的命令?这告诉我您可以访问pubs中的项目,但不能访问工资单。
What happens if you try to run this command from the SQL window? This tells me that you have access to items in pubs, but not payroll.


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

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