Carlos
Carlos

Reputation: 377

How to create a sql batch/job to update a table once a day

i am new in SQL, i am trying to update a table once a day by creating a batch, can anybody please guide me through this. I will really appreciate any help.

This is what i'm trying to accomplish:

  update Products 
  Set DaysLeft =(
          SELECT DATEDIFF(day, getDate(), ExpirationDate) from Products
   )

Upvotes: 1

Views: 3425

Answers (3)

Stuart Ozer
Stuart Ozer

Reputation: 1384

You can use the Azure Automation service to schedule workflows that run on a daily basis in Azure. These workflows can contain any Powershell commands, including commands invoking SQL statements. A good example of using Azure Automation with Azure SQL is covered in this blog: http://azure.microsoft.com/blog/2014/06/26/azure-automation-your-sql-agent-in-the-cloud/

Upvotes: 0

Carlos
Carlos

Reputation: 377

This is what I tried and it works.

  ALTER TABLE Offer 
  ADD daysLeft as (DATEDIFF(day, GETDATE(),ExpirationDate ))

Upvotes: 1

Abhimpi_05
Abhimpi_05

Reputation: 19

You can create a procedure to update a table and then u can create a job calling that procedure , you can keep the frequency of the job everyday at whatever time you want to set .

for job creation you can use DBMS_JOB

Thanks, Abhimpi

Upvotes: 1

Related Questions