Using sp_send_email getting recipents from one query and sending another query results

  • I need to run a job nightly that will get a list of about 20 users with their email address.

    I then need to take the users and get a list sales for those 20 users and email them to the individually.

    What is the best method of doing this should.

    Select username, userid, email from users.

    Then I would I need to

    Select Sales, amt from sales where sales.userid= users.userid

    Then email a seperate report to each of the users.

    The sales report can contain up to 200 line items.

    any help or suggestions is appreciated.

  • I would use a stored procedure to get the list of users, select the results into a temp table and, using a *cough* while loop, send the sproc per user.

    Once that's working, add it to a job step and check it again to make sure the job service account has proper permissions.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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