【问题标题】:BCP Error - SQLState 3700, Native Error = 102BCP 错误 - SQLState 3700,本机错误 = 102
【发布时间】:2014-05-14 01:46:45
【问题描述】:

这是我的 BCPCommand,查询的其余部分已经过测试并且工作正常,我还测试了 BCP 查询中的结果并且也正常

DECLARE @OutputFile VARCHAR(100) ,    
        @FilePath VARCHAR(100) ,    
        @bcpCommand VARCHAR(1000)

SET @bcpCommand = 'bcp "exec [dbo].[spRMAReturnBatchRecords] @strBatchNo = ' + @strBatchNo + 
                  ' , @dtBatchDate = ''' + CONVERT(VARchar(10),@dtBatchDate,120) +
                  ''' , @intBatchNo = ' + CONVERT(varchar(5),@intNextBatchNo) + '" queryout '

SET @FilePath = 'E:\RMA\Test\'
SET @OutputFile = 'RMA-' + @strBatchNo +'.txt'
--SET @bcpCommand = @bcpCommand + @FilePath + @OutputFile + ' -S'+ @@servername + ' -T -c'
SET @bcpCommand = @bcpCommand + @FilePath + @OutputFile + ' -c -T -S ' + @@SERVERNAME
exec master..xp_cmdshell @bcpCommand    
--TEST COMMAND      
--print @bcpCommand
--TEST OUTPUT                     
--exec spRMAReturnBatchRecords @strBatchNo, @dtBatchDate, @intNextBatchNo

我目前收到的错误如下:

Starting copy...
SQLState = 37000, NativeError = 2812
Error = [Microsoft][SQL Server Native Client 11.0][SQL Server]Could not find stored procedure 'spRMAReturnBatchRecords'.
SQLState = S1000, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]Unable to resolve column level collations
BCP copy out failed

当我打印我的 Cmd 时,它的内容如下

bcp "exec [dbo].[spRMAReturnBatchRecords] @strBatchNo = SN001 , @dtBatchDate = '2014-04-02' , @intBatchNo = 1" queryout E:\RMA\Test\RMA-SN001.txt -c -T -S [omitted but correct]

然后,我将“双引号”之间的所有内容粘贴到具有当前连接的新查询中,它可以毫无问题地执行。

exec [spRMAReturnBatchRecords] @strBatchNo = SN006 , @dtBatchDate = '2014-04-02' , @intBatchNo = 6

请帮忙。

【问题讨论】:

  • 试试-d database_name
  • 我很惊讶你在批号周围加上引号;我会期待@strBatchNo = 'SN006'

标签: sql-server bcp xp-cmdshell


【解决方案1】:

尝试将数据库名称添加到查询中:[MyDatabase].[dbo].[spRMAReturnBatchRecords]

根据您期望的输出类型,如果它是逗号分隔的,您可能必须指定一个分隔符(使用 -t ^ 或您喜欢的任何分隔符)。

【讨论】:

    【解决方案2】:

    您也可以在源 SQL 中执行此操作:

    Use DatabaseName
    
    Select column1 from Table1
    

    那么您不必在语句本身中添加限定条件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 2013-08-08
      • 2013-08-08
      • 2012-09-17
      • 2017-01-20
      • 2018-09-29
      • 1970-01-01
      相关资源
      最近更新 更多