sql >> Database >  >> RDS >> Sqlserver

Cursor gebruiken in dbMail in sql server 2008

Ik denk dat je je e-mail binnen de cursor wilt bouwen - iets in de trant van

DECLARE @body nvarchar(max)
DECLARE EmailCursor CURSOR FOR 
  SELECT checknum, checkamt, email FROM .... -- one row per required email

OPEN EmailCursor
FETCH NEXT FROM EmailCursor INTO  @checknum, @checkAmt, @EMAIL
WHILE (@@FETCH_STATUS = 0)
BEGIN
  -- do the bit to build email in here 
  set @body = '<table>'
  select @body = @body + '<tr><td>' + docnum + '</td>'

-- .... rest of fields here
                       + '<td>'+ Cardcode +'</td></tr>'
  from -- .... 
  where checknum = @checknum -- or whatever gives this context
  set @body = @body + '</table>'

  exec  msdb.dbo.sp_send_dbmail -- ...

  FETCH NEXT FROM EmailCursor INTO  @checknum, @checkAmt, @EMAIL
end



  1. pgDash Diagnostische alternatieven - PostgreSQL-querybeheer met ClusterControl

  2. CONCAT gebruiken met MySQL-triggers (fout bij ,)

  3. mysql_fetch_array haalt niet alle rijen op

  4. Encryptie in rust en/of AES_ENCRYPT