IF COUNT > 0 BEGIN
Publicado por leo (3 intervenciones) el 29/04/2021 21:47:29
Buenas tardes para todos. Cómo hago para que esta query se ejecute si sólo si tiene registros el select que está en el cursor? De lo contrario me llegan mails sólo con el header que declaro en el HTML.
Muchas gracias!
Muchas gracias!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
declare @HTMLbody nvarchar(max),
@vtrmvh_codfor varchar(6),
@vtrmvh_nrofor varchar(10),
@vtrmvh_fchmov varchar(50),
@SQL nvarchar(max)
set @SQL = ''
set @HTMLbody = '<html><head><title>Pendientes CAE</title></head><body>'
set @HTMLbody = @HTMLbody + '<center><h1>Pendientes CAE</h1></center>'
set @HTMLbody = @HTMLbody + '<center><table><TH style="background-color:black; color:white">CODFOR</TH><TH style="background-color:black; color:white">NROFOR</TH><TH style="background-color:black; color:white">FECHA</TH>'
DECLARE pendienteCAE cursor
read_only
for
select top 20 vtrmvh_codfor,convert(varchar(10),VTRMVH_NROFOR),vtrmvh_fchmov from VTRMVH
where VTRMVH_CODFOR in (
'CCA005',
'CB0004',
'FB0004',
'DA0005',
'DB0005',
'FB0005',
'CB0005',
'CE0003',
'FCA005',
'DB0004',
'FA0005',
'CA0005',
'DCA005',
'FE0003',
'DE0003') and
VTRMVH_NROCAE is null and
VTRMVH_FCHMOV >= DATEADD(DAY,-10,GETDATE())
order by VTRMVH_FCHMOV desc
open pendienteCAE
fetch next from pendienteCAE into @vtrmvh_codfor,@vtrmvh_nrofor,@vtrmvh_fchmov
WHILE (@@fetch_status <> -1)
BEGIN
set @SQL = @SQL + '<TR><TD style="border:1; border-style:ridge">' + @VTRMVH_CODFOR + '</TD><TD style="border:1; border-style:ridge">' + @VTRMVH_NROFOR + '</TD><TD style="border:1; border-style:ridge">' + @VTRMVH_FCHMOV + '</TD></TR>'
fetch next from pendienteCAE into @vtrmvh_codfor,@vtrmvh_nrofor,@vtrmvh_fchmov
END
CLOSE pendienteCAE
deallocate pendienteCAE
set @HTMLbody = @HTMLbody + @SQL + '</table></center></body></html>'
exec msdb.dbo. sp_send_dbmail
@profile_name = 'Auto Verificaciones',
@recipients = 'lsordello@marlew.com.ar',
@subject = 'Pendientes CAE',
@body = @HTMLbody,
@body_format = 'HTML',
@attach_query_result_as_file = 0 ;
Valora esta pregunta


0