Wednesday, March 25, 2015

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

So I have 3rd party data that I have loaded into a SQL Server Table. I am trying to determine if the 3rd party Members reside in our database by using a cursor and going through all 11,000 rows...substituting the #Parameter Values in a LIKE statement...trying to keep it pretty broad. I tried running this in SQL Server Management Studio and it chunked for about 5 minutes and then just quit. I kind of figured I was pushing the buffer limits within SQL Server Management Studio. So instead I created it as a Stored Procedure and changed my Query Option/Results and checked Discard results after execution . This time it chunked away for 38 minutes and then stopped saying Query completed with errors . I did throw a COMMIT in there thinking that the COMMIT would hit and free up resources and I'd see the Table being loaded in chunks. But that didn't seem to work.


I'm kind of at a loss here in terms of trying to tie back this data.


Can anyone suggest anything on this???


Thanks for your review and am hopeful for a reply.



WHILE (@@FETCH_STATUS=0)
BEGIN
SET @SQLString = 'INSERT INTO [dbo].[FBMCNameMatch]' + @NewLineChar;
SET @SQLString = ' (' + @NewLineChar;
SET @SQLString = ' [FBMCMemberKey],' + @NewLineChar;
SET @SQLString = ' [HFHPMemberNbr]' + @NewLineChar;
SET @SQLString = ' )' + @NewLineChar;
SET @SQLString = 'SELECT ';
SET @SQLString = @SQLString + CAST(@FBMCMemberKey AS VARCHAR) + ',' + @NewLineChar;
SET @SQLString = @SQLString + ' [member].[MEMBER_NBR]' + @NewLineChar;
SET @SQLString = @SQLString + 'FROM [Report].[dbo].[member] ' + @NewLineChar;
SET @SQLString = @SQLString + 'WHERE [member].[NAME_FIRST] LIKE ' + '''' + '%' + @FirstName + '%' + '''' + ' ' + @NewLineChar;
SET @SQLString = @SQLString + 'AND [member].[NAME_LAST] LIKE ' + '''' + '%' + @LastName + '%' + '''' + ' ' + @NewLineChar;

EXEC (@SQLString)
;
--SELECT @SQLReturnValue
--;

SET @CountFBMCNameMatchINSERT = @CountFBMCNameMatchINSERT + 1
;

IF @CountFBMCNameMatchINSERT = 100
BEGIN
COMMIT;
SET @CountFBMCNameMatchINSERT = 0;
END


FETCH NEXT
FROM FBMC_Member_Roster_Cursor
INTO @MemberIdentity,
@FBMCMemberKey,
@ClientName,
@MemberSSN,
@FirstName,
@MiddleInitial,
@LastName,
@AddressLine1,
@AddressLine2,
@City,
@State,
@Zipcode,
@TelephoneNumber,
@BirthDate,
@Gender,
@EmailAddress,
@Relation
END
;

--SELECT *
--FROM [#TempTable_FBMC_Name_Match]
--;

CLOSE FBMC_Member_Roster_Cursor;
DEALLOCATE FBMC_Member_Roster_Cursor;

GO


No comments:

Post a Comment