jjlbmcnews
IS-IT--Management
I'm using the following code in a cursor but I always seem to get one extra row at the end, which appears to be a duplicate of the last row of the table I'm working from. Can anybody point out why its doing this, code below.
DECLARE @vchTextFile varchar(255)
DECLARE @txSummary1 varchar(255)
DECLARE @iState1 varchar(255)
DECLARE @txSummary2 varchar(255)
DECLARE @iState2 varchar(255)
DECLARE @txSummary3 varchar(255)
DECLARE @iState3 varchar(255)
DECLARE @txSummary4 varchar(255)
DECLARE @iState4 varchar(255)
DECLARE @txHeadline varchar(255)
DECLARE @iHeadline varchar(255)
DECLARE SUMM_CURSOR CURSOR FOR
SELECT
.[vchTextFile],
.[txSummary1],
.[iState1],
.[txSummary2],
.[iState2],
.[txSummary3],
.[iState3],
.[txSummary4],
.[iState4],
.[txHeadline],
.[iHeadline]
FROM Summary AS S
OPEN SUMM_CURSOR
FETCH NEXT FROM SUMM_CURSOR
INTO @vchTextFile, @txSummary1, @iState1, @txSummary2, @iState2, @txSummary3,
@iState3, @txSummary4, @iState4, @txHeadline, @iHeadline
SELECT
@vchTextFile,
@txSummary1,
@iState1,
@txSummary2,
@iState2,
@txSummary3,
@iState3,
@txSummary4,
@iState4,
@txHeadline,
@iHeadline
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM SUMM_CURSOR
INTO @vchTextFile, @txSummary1, @iState1, @txSummary2, @iState2, @txSummary3,
@iState3, @txSummary4, @iState4, @txHeadline, @iHeadline
SELECT
@vchTextFile,
@txSummary1,
@iState1,
@txSummary2,
@iState2,
@txSummary3,
@iState3,
@txSummary4,
@iState4,
@txHeadline,
@iHeadline
END
CLOSE SUMM_CURSOR
DEALLOCATE SUMM_CURSOR
DECLARE @vchTextFile varchar(255)
DECLARE @txSummary1 varchar(255)
DECLARE @iState1 varchar(255)
DECLARE @txSummary2 varchar(255)
DECLARE @iState2 varchar(255)
DECLARE @txSummary3 varchar(255)
DECLARE @iState3 varchar(255)
DECLARE @txSummary4 varchar(255)
DECLARE @iState4 varchar(255)
DECLARE @txHeadline varchar(255)
DECLARE @iHeadline varchar(255)
DECLARE SUMM_CURSOR CURSOR FOR
SELECT
FROM Summary AS S
OPEN SUMM_CURSOR
FETCH NEXT FROM SUMM_CURSOR
INTO @vchTextFile, @txSummary1, @iState1, @txSummary2, @iState2, @txSummary3,
@iState3, @txSummary4, @iState4, @txHeadline, @iHeadline
SELECT
@vchTextFile,
@txSummary1,
@iState1,
@txSummary2,
@iState2,
@txSummary3,
@iState3,
@txSummary4,
@iState4,
@txHeadline,
@iHeadline
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM SUMM_CURSOR
INTO @vchTextFile, @txSummary1, @iState1, @txSummary2, @iState2, @txSummary3,
@iState3, @txSummary4, @iState4, @txHeadline, @iHeadline
SELECT
@vchTextFile,
@txSummary1,
@iState1,
@txSummary2,
@iState2,
@txSummary3,
@iState3,
@txSummary4,
@iState4,
@txHeadline,
@iHeadline
END
CLOSE SUMM_CURSOR
DEALLOCATE SUMM_CURSOR