--[C6MartPeriodico].[GESTIONE_SELECT_EMAIL_DA_INVIARE]
CREATE procedure [C6MartPeriodico].[GESTIONE_SELECT_EMAIL_DA_INVIARE_20160913]
AS
BEGIN
SELECT top 800 *
from C6MartPeriodico.MailAvvisoTrimestraleAiPB m
inner join [C6MartPeriodico].[GESTIONE_EMAIL]
  ON GESTIONE_EMAIL.email_id = m.email_id
WHERE isnull(GESTIONE_EMAIL.Inviata,'N')='N'
and testo like '<html>%'
and e_subject is not null
and GESTIONE_EMAIL.email_id NOT IN ('14383','2176','137')
END