Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Sending Email using SQL Job

Sending Email using SQL Job

Scheduled Pinned Locked Moved Database
sharepointdatabasesql-servercomhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Payal_e_m
    wrote on last edited by
    #1

    Hi, I am using SQl 2005 for setting up a job which has 2 steps:- Step 1: Executes a SP which sends out result to a file Type : T-SQL Command : DECLARE @cmd varchar(2000), SET @cmd = 'osql -E -S CONDOR -s";" -w2000 -d Arion -Q"EXEC dbo.ENRSP_Applicants" -o D:\Applicants.txt' EXEC master..xp_cmdshell @cmd Step 2: Mailing the txt file to the user Type : Operating System(CmdExec) Command : "D:\MSSQL\JOBS\EmailFile.cmd" D:\Applicants.txt aa@yahoo.com ss@yahoo.com "Applicants Report" This works fine but the user want some modification to the current Job * the email subject to include the date also * Wants the result set to be dumped into an Excel file and to attach the file to the mail, if there is no results returned no file should be atached * If the Sp doesn't return a result set she wants a message and if it does she wants the message to be another which includes date also. Can all these be done , if so can you plz help me with it? Thanks in advance. Warm regards, Payal

    E 1 Reply Last reply
    0
    • P Payal_e_m

      Hi, I am using SQl 2005 for setting up a job which has 2 steps:- Step 1: Executes a SP which sends out result to a file Type : T-SQL Command : DECLARE @cmd varchar(2000), SET @cmd = 'osql -E -S CONDOR -s";" -w2000 -d Arion -Q"EXEC dbo.ENRSP_Applicants" -o D:\Applicants.txt' EXEC master..xp_cmdshell @cmd Step 2: Mailing the txt file to the user Type : Operating System(CmdExec) Command : "D:\MSSQL\JOBS\EmailFile.cmd" D:\Applicants.txt aa@yahoo.com ss@yahoo.com "Applicants Report" This works fine but the user want some modification to the current Job * the email subject to include the date also * Wants the result set to be dumped into an Excel file and to attach the file to the mail, if there is no results returned no file should be atached * If the Sp doesn't return a result set she wants a message and if it does she wants the message to be another which includes date also. Can all these be done , if so can you plz help me with it? Thanks in advance. Warm regards, Payal

      E Offline
      E Offline
      ElectricLlama
      wrote on last edited by
      #2

      Firstly: is a CSV file acceptable? This opens just in Excel but is easier to create from SQL than an Excel file. If an Excel file is required then you should probably use SSIS (which allows all of this winderfule logic to be implemented)

      P 1 Reply Last reply
      0
      • E ElectricLlama

        Firstly: is a CSV file acceptable? This opens just in Excel but is easier to create from SQL than an Excel file. If an Excel file is required then you should probably use SSIS (which allows all of this winderfule logic to be implemented)

        P Offline
        P Offline
        Payal_e_m
        wrote on last edited by
        #3

        Can you tell me how to proceed(Using SQL job) with a CSV file please? Thanks & regards Payal

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups