본문 바로가기
Database/MS-Sql Lecture

커서 이용하기

by 현이빈이 2008. 8. 22.
반응형

declare  @Duple_Cursor  CURSOR,
 @Staticmenuid integer,
 @DataID integer,
 @DataID2 integer,
 @ImagePath nvarchar(500),
 @ImageFile nvarchar(500)

SET @Duple_Cursor = CURSOR LOCAL SCROLL FOR
select id, staticmenuid, imagepath, imagefile  from viewLinkData

-- 커서를 Open한다.
OPEN @Duple_Cursor

-- Open된 커서에서 정보를 가져온다.
FETCH @Duple_Cursor INTO @Dataid, @Staticmenuid, @imagePath, @ImageFile
WHILE @@FETCH_STATUS = 0
begin
 select @DataID2=id from viewLinkData where staticmenuid=@Staticmenuid and imagePath=@imagePath and imageFile=imageFile and dupleFlag=0 and id<>@DataID
 
  if @DataID2 is not null
  begin
   UPDATE itemlinkData SET DupleFlag = 1 WHERE  ID = @DataID2
   select @DataID2
  end

 FETCH @Duple_Cursor INTO @DataID, @Staticmenuid
end

반응형