Sending SQL query result as email body

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The Programmer
    New Member
    • Apr 2006
    • 2

    Sending SQL query result as email body

    Assistance needed urgently!

    I use a Sybase Database with SQL Anywhere 9 and need to send the SQL query result as the body of the e-mail from within SQL. Here's what I have thusfar:

    =============== =============== =============== ==========

    bEGIN
    SET NOCOUNT ON

    select distinct
    CLient from Client;


    IF @@ROWCOUNT > 0
    BEGIN
    DECLARE @body VARCHAR(1024)

    SET @body = 'Client Names ' +
    CONVERT(VARCHAR , GETDATE()) +
    CHAR(13) + CHAR(10) +
    CONVERT(VARCHAR , @@ROWCOUNT)
    xp_startsmtp( smtp_sender = 'support@test.c o.za', smtp_server = '196.166.8.110' , smtp_port = 25 )
    EXEC master..xp_send mail

    recipients='tes t@test.co.za',
    "message" = @body,
    subject = 'SomeThing123'
    END
    END

    =============== =============== =============== ==========

    Thanks in advance. :confused:
Working...