Wednesday, March 25, 2015

Processing a cursor of 11,000 rows and Query completed with errors

Before we even get to why you're running so slow, execute this:



DECLARE @SQLString NVARCHAR(MAX), @NewLineChar CHAR(1) = CHAR(10)
SET @SQLString = 'INSERT INTO [dbo].[FBMCNameMatch]' + @NewLineChar;
SET @SQLString = ' (' + @NewLineChar;
SET @SQLString = ' [FBMCMemberKey],' + @NewLineChar;
SET @SQLString = ' [HFHPMemberNbr]' + @NewLineChar;
SET @SQLString = ' )' + @NewLineChar;
SET @SQLString = 'SELECT ';


PRINT @SQLString



Your insert is being chewed up because you're not concatenating it... you're setting it to a new value each time...


It's good practice to SELECT your variables and inspect their values when you're doing dSQL like this.




Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.


No comments:

Post a Comment