1

我希望我不会再问..但是..

这是我的 SQL 的相关部分。有问题的视图 (vw_TempALlItems) 是在前面的步骤中创建的,是的,它使用列名创建,并注意类型等。视图 100% 有效。但是 BCP,没那么多。

---------------------------------------------------------------
DECLARE @bcpCommand varchar(2000)

SET @bcpCommand = 'bcp vw_TempAllItems out
"c:\FEPData.csv" -c -t -U USER -P PWD'

EXEC master..xp_cmdshell @bcpCommand
GO

Drop View vw_TempAllItems
GO
----------------------------------------------------------------

我唯一得到的是结果窗格显示了 BCP 命令参数

    usage: bcp {dbtable | query} {in | out | queryout | format} datafile
    [-m maxerrors]            [-f formatfile]          [-e errfile]
    [-F firstrow]             [-L lastrow]             [-b batchsize]
    [-n native type]          [-c character type]      [-w wide character type]
    [-N keep non-text native] [-V file format version] [-q quoted identifier]
    [-C code page specifier]  [-t field terminator]    [-r row terminator]
    [-i inputfile]            [-o outfile]             [-a packetsize]
    [-S server name]          [-U username]            [-P password]
    [-T trusted connection]   [-v version]             [-R regional enable]
    [-k keep null values]     [-E keep identity values]
    [-h "load hints"]         [-x generate xml format file]
    [-d database name]
    NULL

并且未创建 CSV 文件..

任何人?

4

2 回答 2

1

一方面,尝试将其设为查询:

SET @bcpCommand = 'bcp "SELECT * FROM vw_TempAllItems" out
"c:\FEPData.csv" -c -t -U USER -P PWD'

另外,要回答您的问题,请查看: How to pass parameter to a bcp command in sql server on stackoverlow。

于 2013-05-08T15:09:23.663 回答
1

对于任何可能关心这里的人来说,这是效果很好的最终结果

    DECLARE @bcpCommand varchar(2000)
    SET @bcpCommand = 'bcp ' + DB_NAME() + '..vw_TempAllItems out c:\FEPData.csv -c -t, -U User -P Pwd  -S' + @@SERVERNAME
    EXEC master..xp_cmdshell @bcpCommand
    GO
于 2013-05-08T20:04:10.807 回答