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. Deleting Data Using Job Scheduler

Deleting Data Using Job Scheduler

Scheduled Pinned Locked Moved Database
databasequestioncareer
3 Posts 3 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.
  • A Offline
    A Offline
    ASPnoob
    wrote on last edited by
    #1

    Hi all, I would like to delete a record in a SQL database after some time had passed if a certain field in that record has a value of No. For instance I would like to delete a record if the value of the Date field in that record is 5 days passed the timestamp date and the Returns Email field remains No. How do I do that using the Job Scheduler in SQL? I just thought that if I can use the Job Scheduler instead of writing a stored procedure, it would save time. Thanks in advance.

    R M 2 Replies Last reply
    0
    • A ASPnoob

      Hi all, I would like to delete a record in a SQL database after some time had passed if a certain field in that record has a value of No. For instance I would like to delete a record if the value of the Date field in that record is 5 days passed the timestamp date and the Returns Email field remains No. How do I do that using the Job Scheduler in SQL? I just thought that if I can use the Job Scheduler instead of writing a stored procedure, it would save time. Thanks in advance.

      R Offline
      R Offline
      rimazuc
      wrote on last edited by
      #2

      The script below should help. Just modify what is required. Job step as you already know will be T-SQL

      DECLARE @DaysPassed INT -- Number of days required for record deletion
      SELECT @DaysPassed = DATEDIFF(DD,GETDATE() - 5, GETDATE()) -- Diff in days eg (GETDATE() - 5, GETDATE() = today - (today - 5)
      IF @DaysPassed = 5 -- If days paseed = 5 then...
      BEGIN
      SELECT GETDATE() -- Your delete statement can go here.
      END
      ELSE
      PRINT 'I love Code project' -- If not equal to 5 then....
      GO

      Cheers

      1 Reply Last reply
      0
      • A ASPnoob

        Hi all, I would like to delete a record in a SQL database after some time had passed if a certain field in that record has a value of No. For instance I would like to delete a record if the value of the Date field in that record is 5 days passed the timestamp date and the Returns Email field remains No. How do I do that using the Job Scheduler in SQL? I just thought that if I can use the Job Scheduler instead of writing a stored procedure, it would save time. Thanks in advance.

        M Offline
        M Offline
        Michael Potter
        wrote on last edited by
        #3

        DELETE
        [TableName]
        WHERE
        [TimeColName] < DATEADD(dd,-5,GETDATE()) AND
        [EmailColName] = 'No'

        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