상세 컨텐츠

본문 제목

cursor 예제

Programming/ms-sql

by luckey 2011. 2. 18. 18:19

본문


declare @idx int
declare @mIdx int
declare @cIdx int
set @idx = 0

set nocount on

create table #Test(idx int, memberIdx int, collageIdx int, regDate datetime, mID varchar(30), mPwd varchar(30))

declare cur_Test Cursor FOR

select memberIdx, collageIdx from memberExcel as A
inner join lectureExcel as B
on A.idx = B.memberExcelIDx
where excelDefaultIdx = 1
group by memberIdx, collageIdx

open cur_Test
fetch next from cur_Test into @mIDx, @cIdx

while @@FETCH_STATUS = 0
begin

 set @idx = @idx + 1
 insert into #Test values (@idx, @mIdx, @cIdx, getDate(), '0000', '0000')
 fetch next from Cur_test into @mIdx, @cIdx

nd

set nocount off

select * from #Test
close cur_Test
deallocate cur_Test

drop table #Test

관련글 더보기

댓글 영역