-
MS-SQL 커서 활용법 Cursor프로그램/Mssql 2024. 1. 23. 11:52반응형
DECLARE @scode char(6)
DECLARE @i INT
SET @i=0
DECLARE Ncursor CURSOR FOR
select s_code from tb_student where s_code=학생코드
OPEN Ncursor
FETCH NEXT FROM Ncursor INTO @scode
WHILE @@fetch_status = 0
BEGIN
delete from tb_nowtable1 where s_code=@scode
delete from tb_nowtable2 where s_code=@scode
delete from tb_nowtable3 where mb_id=@scode
delete from tb_nowtable4 where s_code=@scode
FETCH NEXT FROM Ncursor INTO @scode
SET @i=@i+1
END
CLOSE Ncursor
DEALLOCATE Ncursor
select @i
select s_code from tb_student where s_code=학생코드
@@@@@@@@@@# --두개의 조건값을 가지고 비교해야할 경우 @@@@@@@@@@@@############
DECLARE @scode char(6)
DECLARE @brcode char(4)
DECLARE @i INT
SET @i=0
DECLARE Ncursor CURSOR FOR
select s_code,br_code from 테이블
OPEN Ncursor
FETCH NEXT FROM Ncursor INTO @scode, @brcode
WHILE @@fetch_status = 0
BEGIN
-- select @scode, @brcode
-- select * from 테이블 where s_code=@scode and br_code=@brcode
FETCH NEXT FROM Ncursor INTO @scode, @brcode
SET @i=@i+1
END
CLOSE Ncursor
DEALLOCATE Ncursor
select @i반응형'프로그램 > Mssql' 카테고리의 다른 글
MS-SQL 트리거 인서트(insert)시 업데이트(update) (0) 2024.01.23 MS-SQL 테이블 용량(크기) 확인 하는 방법 (0) 2024.01.23 MS-SQL 주민번호 체크 쿼리 (0) 2024.01.23 MS-SQL 프로시져 내용 검색 (0) 2024.01.23 MS-SQL 배열을 이용한 프로시저 (1) 2024.01.23