Forum Discussion

TheTallman's avatar
TheTallman
Copper Contributor
Jul 08, 2021

SQL: need to create a sql job

Hi Team, I want to automate one of my SQL project and need help for same. I’m inserting a data in my dimension table on production server from our reference server based on any new row found in reference table.  I’d like implement following things to get it automate ..

 

Query ..

INSERT INTO PROD_DB.[dbo].[DimAccount]

Select * from Ref01.REF_DB.[dbo].[DimAccount] D1 left join PROD_DB.[dbo].[DimAccount] D2 on D1.ID=D2.ID where ID is null

 

Create a job that should run Bi weekly  to run update query by itself and produce such results in pdf or excel.

 

 

 

1 Reply

  • PradeeRaturi's avatar
    PradeeRaturi
    Copper Contributor

    Hi,

    It would be beneficial to place this query inside a stored procedure and schedule a job to execute it automatically. You can also export the output in Excel, .txt, or HTML format.

    Here are two articles for your reference: the first one explains how to create jobs in SQL Server, and the second covers how to send query results in the email body as a .txt file. These resources may be helpful for your requirements.


    https://sqlskull.com/2019/12/14/schedule-a-job-in-sql/
    https://sqlskull.com/2020/03/07/how-to-send-a-sql-server-query-results-in-e-mail-message/

Resources