Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

BCP reports no errors but inserts no rows

$
0
0
Hi all,I have a Job that creates .CSV files at predetermined intervals (the delimiter is a tabstop) and every 5 minutes I have to retrieve These files one at a time and Import them into the relevant database.My solution was to create a list of the files and insert this list into a temporary table where a Cursor would extract each filename one at a time and insert that Name into a BCP Statement. The BCP Statement is constructed using dynamic SQL.Here the Cursor:[code="SQL"]create table #filelist(filename nvarchar(100))insert into #filelist exec xp_cmdshell 'dir C:\BCP_Test /A-D /B'declare @filename nvarchar(100)declare @path nvarchar(100)declare @bcp_open nvarchar(100)declare @params nvarchar(100)declare @filepath nvarchar(100)declare @bcpcmd nvarchar(max)set @bcp_open = 'bcp HumanResources.Employee2 in 'set @path = 'C:\BCP_Test\'set @params = ' -T -d AdventureWorks2014 -S .\SQLSERVER -F2 -n -k'declare curBulkImport cursor forward_only static read_only for select filename from #filelist where filename is not null order by filename asc; open curBulkImport;while @@FETCH_STATUS = 0begin fetch next from curBulkImport into @filename set @filepath = @path + @filename set @bcpcmd = (@bcp_open + @filepath + @params) exec xp_cmdshell @bcpcmd end;deallocate curBulkImportdrop table #filelist [/code]The code seems to work but although there are around 50000 lines in the .csv file, None of the lines are inserted. Can anyone help? I am losing more hair with each execution..... :)RegardsKev

Viewing all articles
Browse latest Browse all 3145

Trending Articles