DECLARE @dbname VarChar (30)
-- =============================================
-- Déclaration des variables
DECLARE @Cpt Int
DECLARE @Act char(3)
DECLARE @Dep char(3)
DECLARE @Ann char(3)
DECLARE @Rec int
DECLARE @Lig int
DECLARE @Err varchar(256)
DECLARE @Mail varchar(1024)
DECLARE Curseur1 CURSOR
FOR select r1cact, r1cdpo, r1nann, r1nrec, r1nlir from reflex.hlreclp,reflex.hlrecpp where r1nann = '5' and R1QBVR = '0'
and recact = r1cact and recdpo = r1cdpo and renann = r1nann and renrec = r1nrec and retmev = '1' and RETRVA ='0'
-- =============================================
SET @dbname = 'RFXCOOPPROD'
EXEC ('USE ' + @dbname)
select @Cpt=count(*) from reflex.hlreclp,reflex.hlrecpp where r1nann = '5' and R1QBVR = '0'
and recact = r1cact and recdpo = r1cdpo and renann = r1nann and renrec = r1nrec and retmev = '1' and RETRVA ='0'
if @Cpt <> 0
-- =============================================
-- Si une ou plusieurs lignes contiennent les paramètres ci dessus, alors envoi
-- email à
xxxxxxxx@mondomaine.lan
-- =============================================
begin
set @Mail = ''
OPEN Curseur1
FETCH Curseur1 INTO @Act, @Dep, @Ann, @Rec, @Lig
WHILE @@FETCH_STATUS = 0
BEGIN
set @Err = @Act + ' ' + @Dep + ' ' + convert(varchar,@Ann) + ' ' + convert(varchar,@Rec) + ' ' + convert(varchar,@Lig)
if not exists(select * from reflex.hlw000p where hlcssn = 'RECDEBUG' and wekobj=@Err)
begin
insert into reflex.hlw000p (hlcssn,WENRGP,wekobj) values('RECDEBUG','1',@Err)
set @Mail = @Mail + ' ' + @Err + '<br>'
end
FETCH Curseur1 INTO @Act, @Dep, @Ann, @Rec, @Lig
end
CLOSE Curseur1
DEALLOCATE Curseur1
if @Mail <> ''
begin
EXEC msdb.dbo.sp_send_dbmail @recipients='ssaumon@coopatl.lan',
@subject = 'Reception en erreur',
@body = @Mail,
@body_format = 'HTML'
end
end
Partager