set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go CREATE TRIGGER [ASSINATURA_DIRETORIA] ON [dbo].[TMOVAPROVA] FOR INSERT AS DECLARE @IDMOV INT DECLARE CURSORMOV CURSOR FOR SELECT A.IDMOV from tmovaprova a,TMOV b, Gusuario c WHERE a.IDMOV=b.idmov and a.codusuario=c.CODUSUARIO and b.codtmv in('1.1.01','1.1.02') AND B.CAMPOLIVRE1 IS NULL OPEN CURSORMOV FETCH NEXT FROM CURSORMOV INTO @IDMOV WHILE @@FETCH_STATUS = 0 BEGIN UPDATE TMOV SET CAMPOLIVRE1= + 'Aprovador Por - '+ CONVERT(VARCHAR(25),C.NOME,103)+'- Dia - '+ CONVERT(VARCHAR(20),a.horarioaprovacao,103)+ ' as ' + convert(varchar, a.horarioaprovacao,108) from tmovaprova a,TMOV b, Gusuario c WHERE a.IDMOV=b.idmov and a.codusuario=c.CODUSUARIO and b.codtmv in('1.1.01','1.1.02') AND B.CAMPOLIVRE1 IS NULL AND A.IDMOV = @IDMOV FETCH NEXT FROM CURSORMOV INTO @IDMOV END CLOSE CURSORMOV DEALLOCATE CURSORMOV