How can i run Stored Procedures only if

  • how can i run Stored Procedures the send email

    but ony in condition

    if the table is not empty

    this is my select

    ---------------

    SELECT * FROM [mira].[dbo].[UserBirthDay] WHERE (BirthdayToday = 1)

    ---------------------------------------

    this is my Stored Procedures

    and i wont thet if the table is empty

    thet the email will not send !!

    ------------------

    DECLARE @recipient VARCHAR(1000)

    DECLARE @pstrNames VARCHAR(8000)

    SET @pstrNames = ''

    -- Append all results into a variable

    SELECT @pstrNames = @pstrNames + ISNULL(email, '') + ';'

    FROM dbo.em

    -- Remove the comma at the end

    IF ( RIGHT(@pstrNames, 1) = ',' )

    SET @pstrNames = LEFT(@pstrNames, LEN(@pstrNames) - 1)

    select @pstrNames

    exec master.dbo.xp_SMTPSendMail80

    @query='SELECT * FROM [mira].[dbo].[UserBirthDay] WHERE (BirthdayToday = 1) ',

    @address='out.zahav.net.il',

    @subject='Subject Line',

    @from='midan1@zahav.net.il',

    @html=1, -- Send the results as html

    @Body='<html><header>header</header><body>Body Text</html></body>',

    @qTableCaption='This is a Caption',

    @qTableAttribute='border=2',

    @recipient=@pstrNames

    ----------------------------

    thnks ilan

  • IF EXISTS( SELECT 1 FROM mira.dbo.UserBirthDay WHERE BirthdayToday = 1 )

    BEGIN

    -- put your emailing code here...

    END

    Also, if your current database is [mira], I suggest you remove [mira]. from the table qualification. Since you are specifying the database name, DTC (Distributed Transactions Coordinator) is getting involved unnecessarily. Shalom.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply