SQL游标使用

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


Alter                        PROC Cg_Input_Jz
@dprovider varchar(4),
@ddate varchar(10)
AS
BEGIN TRANSACTION
DECLARE @Sqlstr Varchar(200)
DECLARE @Dticket_no Varchar(18)
  /*SET @SqlStr ='delete from ticket_gscg_cg where dprovider='+char(39)+@dprovider+char(39)
exec (@SqlStr)
  SET @SqlStr='delete from sldata_tdx.dbo.ticket_cg where dticket_no not in(select dticket_no from v_items_cg) and dstate_run=0'
exec (@SqlStr)*/
    DECLARE dticket_no CURSOR
    FOR select dticket_no from sldata_tdx.dbo.ticket_cg where dworker='0036' and dprovider=@dprovider and dstate_run=0
    OPEN dticket_no
    FETCH NEXT FROM dticket_no INTO @Dticket_no
    while(@@fetch_status=0)       
    BEGIN   
      Exec sldata_tdx.dbo.r_ticketaudit @Dticket_no,'0001','0036',@ddate
      FETCH NEXT FROM dticket_no INTO @dticket_no
    END
    CLOSE dticket_no
    DEALLOCATE dticket_no
COMMIT TRANSACTION
RETURN  

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

 

你可能感兴趣的:(sql,Go)