Como enviar um e-mail quando um campo de uma tabela for alterado.

Osman Ferreira De Almeida 0 Reputation points
2023-10-23T20:49:25.3966667+00:00

Caros, Boa tarde, por favor, tenho uma query que registra como um solicitante definiu um campo, porem tem etapas que um aprovador possa alterar este campo.
Preciso que, se o aprovador alterasse este campo, um e-mail fosse enviado alertando que aquele campo foi alterado em relação a solicitação original.

Segue query para analise..

SELECT DISTINCT S.SOL_COD 'Protocolo', TM2.CODIGO 'Tipo Requisitante', TM.CODIGO 'Tipo Finalizado' FROM SOLICITACAO S

LEFT JOIN TIPO_MATERIAL TM ON S.TMA_COD = TM.TMA_COD

LEFT JOIN SOL_RESPOSTA SR ON S.SOL_COD = SR.SOL_COD

LEFT JOIN RES_PERG_TMA RP ON SR.RES_COD = RP.RES_COD

LEFT JOIN TIPO_MATERIAL TM2 ON RP.TMA_COD = TM2.TMA_COD

WHERE S.CODMAT = 0 AND S.STATUS = 5 AND TM2.CODIGO IS NOT NULL AND TM.CODIGO <> TM2.CODIGO

Segue resultado da query..

User's image

Grato, No aguardo..

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,899 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 102.3K Reputation points
    2023-10-23T21:19:44.2433333+00:00

    Por lo primero: el lenguaje de ese forum es ingles. Puedo leer portuguesa un poco, mas non puedo escribir en portuguesa.

    .....................................................

    First of all, this is a en English-language forum. I can read Portuguese to some extent, but I can't really speak it. (Which is why the above was in Spanish.)

    Write a program (Powershell, C# or whatever) that you schedule through Agent or Task Scheduler which runs this query and saves data into a table, and on next execution compares the result with that is saved. If it has, send the mail from the program. Yes, you can send mail from SQL Server, but just because you can, does not mean that you should.

    0 comments No comments

  2. CosmogHong-MSFT 23,716 Reputation points Microsoft Vendor
    2023-10-24T02:26:15.7233333+00:00

    Hi @Osman Ferreira De Almeida

    If you are interested in keeping track of schema changes and send alert emails, then you might refer to the solution in this article: Send Email Alert on Database Schema Change in SQL Server.

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments