Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    37

    Unanswered: Question unrelated to cursors (was "Cursors")

    hi
    how to send notifications like alert and emails in sql

    Thanks

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Version of SQL Server?
    Also, cursors have nothing to do with it.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    One method to send an email
    Code:
    DECLARE @message_body	   nvarchar(max) 
          , @email_recipient varchar(255)
    
    SET @email_recipient = 'example@example.com'
    SET @message_body    = N'<b>test email</b>'
    			               + N'<p>meh</p>'
    
    EXEC msdb..sp_send_dbmail
       @profile_name = '<profile name>'
     , @recipients   = @email_recipient
     , @subject	     = 'Email Subject'
     , @body         = @message_body
     , @body_format  = 'HTML'
    And an example cursor
    Code:
    DECLARE @email_address varchar(255)
    
    DECLARE email_cursor CURSOR FOR
      SELECT email_address
      FROM   dbo.customers
      WHERE  email_address > ''
      AND    opt_out_email = 0
    
    OPEN email_cursor
    
    FETCH NEXT FROM email_cursor INTO @email_address
    
    WHILE @@Fetch_Status = 0
      BEGIN
        PRINT @email_address
    
        FETCH NEXT FROM email_cursor INTO @email_address
      END
    
    CLOSE email_cursor
    DEALLOCATE email_cursor
    let us know if you have trouble combining them
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •