Well, first of all .. (and sorry for that;)) DON "T USE CURSORS .. and sorry for the caps ...
One of the worst things about cursors is that they can lock your table. What I always do for these purposes (and it's pretty fast), I use a for loop ... like this
declare @totrow int , @currow int , @result int , @nsql nvarchar(max) declare @sqlStatements table ( Id int identity(1, 1) , SqlStatement varchar(max) ) insert into @sqlStatements select 'QUERY PART' from table set @totrow = @@rowcount set @currow = 1 while @totrow > 0 and @currow <= @totrow begin select @nsql = SqlStatement from @SqlStatements where Id = @currow exec @result = xp_cmdshell @nsql set @currow = @currow + 1 end
In the next part, does the SQL Server process have sufficient permission to write to the c drive: Also, look in the message bar when you execute your code, maybe you can find something there?
What you can do as well, try doing it manually. Just get one BCP statement and execute it using xp_cmdshell. Does this give any errors?
Mark kremers
source share