BCP语法问题 [英] BCP Syntax issues

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

问题描述

所有,我正在尝试编写一个查询,该查询每天可以从SQL Server 2008实例上的批处理文件运行.

All, I'm trying to write a query that I can run daily from a batch file on a SQL server 2008 instance.

我以前从未使用过BCP,但是在网上查看了一些示例之后,我尝试创建一个真正的基本查询来测试流程和&在将选择查询范围扩大到所需数据集之前,先对计算机具有权限.

I've never used BCP before but after looking at some examples online, I've tried to create a real basic query to test the process & permissions on the machine before I look to widen the select query to the required dataset.

我正在使用:

 bcp    
"SELECT manifest_dt from EasyShip_050300.airwaybills"
queryout C:\Shares\DHL-EXPORT-TEST\file.txt -SGRENSON-CARRIER\DHLEASYSHIP -c -T

似乎几乎可以在网上找到所有示例,但每次执行此查询时,我都会收到错误消息:

It appears to match nearly every example I can find online but everytime I execute this query I receive the error:

Msg 102, Level 15, State 1, Line 6
Incorrect syntax near 'queryout'.

如果有人有任何指针,将不胜感激.

If anybody has any pointers it would be appreciated.

推荐答案

让我用两个我知道可以在我的环境中使用的通用命令进行回复(使用受信任的连接).看看他们是否也对您有用,并从那里开始工作:

Let me reply with two generic commands that I know to work in my environment (using trusted connection). See if they work on yours too, and work from there:

-- default row separator, column separator
DECLARE @stmt VARCHAR(8000);
SET @stmt=
    'BCP '+
    '"SELECT*FROM INFORMATION_SCHEMA.TABLES" '+
    'QUERYOUT "C:\Temp\information_schema.txt" '+
    '-c -T -S ' + @@SERVERNAME + ' -d ' + DB_NAME();
EXEC master.sys.xp_cmdshell @stmt;

-- comma separated:
DECLARE @stmt_c VARCHAR(8000);
SET @stmt_c=
    'BCP '+
    '"SELECT*FROM '+QUOTENAME(DB_NAME())+'.INFORMATION_SCHEMA.TABLES" '+
    'QUERYOUT "C:\Temp\information_schema.csv" '+
    '-c -t, -T -S ' + @@SERVERNAME;
EXEC master.sys.xp_cmdshell @stmt_c;

如果它们起作用,请SELECT @stmt_c; SELECT @stmt;并查看它们的形成方式.然后查看您的命令有什么区别.

If they work, SELECT @stmt_c; SELECT @stmt; and see how they are formed. Then see what the difference is with your commands.

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

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