存储过程之游标(SqlServer)

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


CREATE    PROCEDURE [dbo].[invest_Approve_Check] AS
declare @declareNo varchar(50)
declare @item_name varchar(200)
declare @deadLine datetime

begin transaction

declare my_cursor cursor scroll
for 

	SELECT  ITEMNAME, DEADLINE, DECLARENO
	FROM JDJC_ITEMADVICE
	--WHERE 

open my_cursor
fetch next from my_cursor into @item_name,@deadLine,@declareNo
while(@@fetch_status=0)
begin
----------------------------------------------------------------------------------------------------------------------
	if(select count(*) FROM invest_supervise_info where item_id = @declareNO and type = 117001) = 0
	begin
		insert INTO invest_supervise_info (item_id,item_name,class,type,deadline,jiancha_person) values(@declareNo,@item_name,117,117001,getdate(),61)
	end
----------------------------------------------------------------------------------------------------------------------
fetch next from my_cursor into @item_name,@deadLine,@declareNo
end
close my_cursor
deallocate my_cursor
--游标结束


    if(@@error>0)
		begin
			rollback tran
			select 0
			return
		end
    else	
		begin
			commit tran
			select 1
			return
		end

你可能感兴趣的:(Go)