user3490224
user3490224

Reputation: 21

BCP Error - SQLState 3700, Native Error = 102

Here is my BCPCommand, the rest of the query is tested and working fine, I have also tested the results in the BCP Query and is also in order

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

The errors I am receiving currently are as follow:

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

When I print my Cmd it reads as follows

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]

I then paste everything between the "double quotes" into a new query with current connections and it executes without problems.

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

Please assist.

Upvotes: 2

Views: 5724

Answers (2)

one angry researcher
one angry researcher

Reputation: 612

Try adding the name of the database to the query: [MyDatabase].[dbo].[spRMAReturnBatchRecords].

Depending on the kind of output you expect, you might have to specify a separator if it's comma separated (use -t ^ or whatever separator you like).

Upvotes: 1

user5003923
user5003923

Reputation: 1

You can also do this in your source SQL:

Use DatabaseName

Select column1 from Table1

Then you don't have to add the qualification in the statement itself.

Upvotes: 0

Related Questions