Hi,

Im trying to trigger an email from the code below.
The email should be send if % rise of AvgTemp is higher then 10%.
Any suggestions?
declare temp table
(
[id] [int] IDENTITY(1,1) NOT NULL,
[Dag] [datetime],
[Locatie] [NVARCHAR] (MAX),
[Temperatuur] [int]
)
insert temp ([Dag], [Locatie], [Temperatuur])
VALUES('20111112','Rotterdam','12');
insert temp ([Dag], [Locatie], [Temperatuur])
VALUES('20111231','Rotterdam','12');
insert temp ([Dag], [Locatie], [Temperatuur])
VALUES('20120118','Rotterdam','9');
insert temp ([Dag], [Locatie], [Temperatuur])
VALUES('20120213','Rotterdam','5');
insert temp ([Dag], [Locatie], [Temperatuur])
VALUES('20120214','Rotterdam','7');
insert temp ([Dag], [Locatie], [Temperatuur])
VALUES('20120215','Rotterdam','4');
insert temp ([Dag], [Locatie], [Temperatuur])
VALUES('20120316','Rotterdam','4');
insert temp ([Dag], [Locatie], [Temperatuur])
VALUES('20120418','Rotterdam','10');
insert temp ([Dag], [Locatie], [Temperatuur])
VALUES('20120501','Rotterdam','10');
insert temp ([Dag], [Locatie], [Temperatuur])
VALUES('20110501','Rotterdam','7');

SELECT month(Dag) AS [Maand], year(Dag) AS [Jaar], locatie, avg(Temperatuur) AS [GemTemp]
FROM TEMP
group by year(Dag), month(Dag), locatie
ORDER BY year(Dag) desc, month(Dag), locatie;


with TEMP as
(
SELECT year(Dag) as ThisYear, month(Dag) AS [Maand], avg(Temperatuur) AS [AvTemp]
FROM TEMP
group by year(Dag), month(Dag)
)
select c1.Maand, c1.AvTemp, '%_stijging' = convert(decimal(8,2),(1.0*(c1.AvTemp-c2.AvTemp)/c2.AvTemp)*100)
from TEMP c1
left join TEMP c2
on dateadd(mm, c2.Maand - 1, dateadd(yy, c2.ThisYear - 1900, 0)) = dateadd(mm, -1, dateadd(mm, c1.Maand - 1, dateadd(yy, c1.ThisYear - 1900, 0)))
order by dateadd(mm, c1.Maand - 1, dateadd(yy, c1.ThisYear - 1900, 0));