2

Background: I created an application that measures a weight from a scale and saves the information in MS SQL server database.

In the database, I want to save a record for the actual weight for every day as historical, and I don’t know what I have to use to accomplish this task.

Can a trigger in SQL Server do it ??

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
Akrem
  • 5,033
  • 8
  • 37
  • 64
  • Is this application that you created a windows application that you want to run every day at a specified time? – TheBoyan Jul 21 '11 at 17:20
  • We need a little more information for what you are trying to do to give an accurate answer. Do you wish to save all of the weight entries to a historical table? Do you wish to save only the highest weight to the historical table? Do you want this to happen according to what time it is or is there an event that signals when to do this. – Bueller Jul 21 '11 at 17:21
  • If it's a win app take a look at the following thread: http://stackoverflow.com/questions/4583614/c-code-run-at-9-00-pm-every-day-automatic – TheBoyan Jul 21 '11 at 17:23
  • the application work 24/24 and I want to save the actual weight in mid night ... to be in code or in sql server I don't have problem – Akrem Jul 21 '11 at 17:24
  • @bojanskr : I don't want to use windows scheduled task – Akrem Jul 21 '11 at 17:27
  • @Akrem : OK, in that case you should be more specific on the term application in the question. That's what lead me to believe that it was a win app. – TheBoyan Jul 21 '11 at 17:35

3 Answers3

8

You don't need to try and hack this with a trigger. In SQL Server this type of feature (scheduled execution) is easily managed with a SQL Server Job. You would just create a SQL Server job that runs once a day and executes whatever T-SQL you need to meet the biz logic requirement.

So you don't actually need to code anything else. Just configure a job and set its schedule. You do not need another application. SQL Server already manages scheduled execution with SQL Agent.

Do note that the SQL Server Jobs feature is not available with SQL Server Express editions.

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
2

Simple approach: use Windows Scheduler.

If this approach is too simple then create windows service and use Quartz.NET in your implementation to have trigger functionality.

empi
  • 15,755
  • 8
  • 62
  • 78
-1

If you need to run a scheduled task/cron job in a shared hosting environment, you'll find a list of free web cron job providers here: ASP.NET: Free scheduling of your tasks (Cron jobs)

Ulf
  • 1