Sending an email with multiple variables

  • I was wondering the most efficient way to send an email that has multiple variables. For example I have a stored proc that sends the email and in the body of the email I need to pull info from one table, 4 different columns. What is the most efficient way to do this?? At the present my idea is to do this..

    DECLARE @var1 as varchar(10), @var2 as varchar(10), @var3 as varchar(10), @var4 as varchar(10)

    SET @var1 = (Select column from table where..)

    SET @var2 = (Select column2 from table where..)

    ETC...

    Then in the email body call each @var....

    Is there a better way to do this??

  • if the data is all in the same row, you can do this:a assuming my table has the columns in capitals:

    SELECT

    @var1=SUBJECT,

    @var2=EMAILFROM,

    @var3=EMAILTO,

    @var4=SUBJECT

    FROM PENDINGEMAILS WHERE SUCCESSFULLYSET=0

    if they are coming form different WHERE conditions or otehr tables, then you'd need to do a few more, but the idea is you can assign the values in the SELECT statement(assuming there's only one row to grab)

    Juan Ordonez (8/13/2008)


    I was wondering the most efficient way to send an email that has multiple variables. For example I have a stored proc that sends the email and in the body of the email I need to pull info from one table, 4 different columns. What is the most efficient way to do this?? At the present my idea is to do this..

    DECLARE @var1 as varchar(10), @var2 as varchar(10), @var3 as varchar(10), @var4 as varchar(10)

    SET @var1 = (Select column from table where..)

    SET @var2 = (Select column2 from table where..)

    ETC...

    Then in the email body call each @var....

    Is there a better way to do this??

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Perfect, thanks Lowell

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

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