franglais
franglais

Reputation: 938

Error using BCP to export data from SQL Server 2008

I'm getting the error:

SQLState = S1000, NativeError = 0 Error = [Microsoft][SQL Server Native Client 10.0]Unable to open BCP host data-file

When running the following command:

set nocount on;
Declare @sql varchar(1000);
declare @noteid int;
declare xx1 cursor for select nic.NotebookItemId from NotebookItemContent nic
inner join NotebookLinks nl on nl.NotebookItemId = nic.NotebookItemId
inner join NotebookItems ni on ni.NotebookItemId = nic.NotebookItemId
where nl.clientid = 1235074
AND ni.NotebookTypeId = 56;
open xx1;
fetch xx1 into @noteid;
while (@@fetch_status = 0)
begin
set @sql = 'BCP "SELECT memo FROM Monarch_Pronet_ITOIL.dbo.notebookitemcontent where notebookitemid=' + cast(@noteid as varchar) + 
'" QUERYOUT C:\TEMP\' + cast(@noteid as varchar) + '.doc -T -f C:\temp\bcp.fmt -S ' + @@SERVERNAME
EXEC master.dbo.xp_CmdShell @sql
fetch xx1 into @noteid;
end;
close xx1;
deallocate xx1;

Any help would be appreciated!

Print @SQL returns:

BCP "SELECT memo FROM Monarch_Pronet_ITOIL.dbo.notebookitemcontent where notebookitemid=17695498" QUERYOUT C:\TEMP\17695498.doc -T -f C:\temp\bcp.fmt -S BHAMSQL-SRV03

Also realised my original query wasn't right (was selecting all memo rather than using the cursor...! so the correct query is now the one above - apologies for me being a muppet :D

Upvotes: 2

Views: 4116

Answers (1)

rvphx
rvphx

Reputation: 2402

Can you do a

PRINT @sql 

and see what the @sql string value is. I am guessing, its a misplaced quote or a backslash

Upvotes: 2

Related Questions