Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ALTER TRIGGER [dbo].[asocia_ia_prest] ON [dbo].[GPF_DETALLE] FOR INSERT
- AS
- BEGIN
- DECLARE @CORRELLOTE NUMERIC(9)
- DECLARE @CORRELPW NUMERIC(9)
- DECLARE @GPF_CORREL NUMERIC(5)
- CREATE TABLE #tabla(ID NUMERIC(8) IDENTITY(1,1), iad_codigo CHAR(2), prs_correl NUMERIC(5))
- SET @GPF_CORREL = (SELECT top 1 gpf_correl FROM INSERTED)
- IF EXISTS (SELECT iad_codigo FROM INSERTED WHERE iad_codigo IS NOT NULL /*and prs_correl is null*/)
- BEGIN
- DECLARE @IAD_CODIGO CHAR(2)
- DECLARE @PRS_CORREL NUMERIC(5)
- DECLARE @RowCount INT
- DECLARE @I INT
- INSERT INTO #tabla(iad_codigo, prs_correl)
- SELECT pria.IAD_CODIGO, pria.PRS_CORREL
- FROM PRESTACION_IA pria (nolock)
- WHERE pria.IAD_CODIGO IN (SELECT IAD_CODIGO FROM INSERTED WHERE prs_correl IS NULL)
- ORDER BY pria.IAD_CODIGO, pria.PRS_CORREL
- SET @RowCount = (SELECT COUNT(ID) FROM #tabla)
- SET @I = (SELECT top 1 id FROM #tabla)
- EXEC @CORRELLOTE = [dbo].[spu_get_correl_lote] 'GPF_DETALLE', @RowCount
- SET @CORRELPW = @CORRELLOTE - @RowCount + 1
- WHILE (/*@I <= @RowCount AND*/ @CORRELPW <= @CORRELLOTE)
- BEGIN
- SELECT @IAD_CODIGO = iad_codigo, @PRS_CORREL = prs_correl FROM #tabla WHERE ID = @I
- INSERT INTO GPF_DETALLE (GPD_CORREL, GPF_CORREL, IAD_CODIGO, PRO_CORREL, PRS_CORREL)
- VALUES (@CORRELPW, @GPF_CORREL, @IAD_CODIGO, NULL, @PRS_CORREL)
- SET @CORRELPW = @CORRELPW+1
- SET @I = @I + 1
- END
- END
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement