+ Reply to Thread
Results 1 to 6 of 6

Thread: SQL Job or stored procedure

  1. #1
    Barn Loyal todd2006 is an unknown quantity at this point todd2006's Avatar
    Join Date
    Mar 2008
    Posts
    889
    Rep Power
    4

    SQL Job or stored procedure

    Hi,

    Can someone guide me in the right direction.

    I have table called Registration_Deadline design is like this

    Id
    Name
    Email
    DateTime
    Cost

    then there is another table called Registration

    ID
    Reg_Id
    Name
    Address
    AmountPaid

    What I have to do is if the date in Registration_deadline is one day older then todays date I want to get all the records for that registration from the registration table.

    I want to create a excel sheet and then email that excel sheet to a person at midnight

    Can someone tell me where I should start.

    Todd

  2. #2
    Barn Newbie Memnoch will become famous soon enough Memnoch's Avatar
    Join Date
    Nov 2008
    Location
    Missouri
    Posts
    38
    Blog Entries
    1
    Rep Power
    4

    Are there keys linking the two tables together? If so, which ones?
    Being educated does not make you intelligent.

  3. #3
    Barn Loyal todd2006 is an unknown quantity at this point todd2006's Avatar
    Join Date
    Mar 2008
    Posts
    889
    Rep Power
    4

    Hello,

    Id is the primary key in Registration_deadline table and Reg_Id is the foreign key in the Registration table.

  4. #4
    Barn Newbie Memnoch will become famous soon enough Memnoch's Avatar
    Join Date
    Nov 2008
    Location
    Missouri
    Posts
    38
    Blog Entries
    1
    Rep Power
    4

    Might I suggest the following design...

    Note: I'm not sure why you have a "Name" column in your RegDeadline table, when one already exists in your Registration table. I am also not sure whey you have an "Email" column in your RegDeadline table, as that column would be more appropriately associated with the entity stored in the Registration table. Not sure why you have a "Cost" column in your RegDeadline table, that would be more appropriately associated with the entity in your Registration table. The "AmountPaid" column would be more appropriate for the RegDeadline table.

    Below is a best practice design, which adhere's to proper naming conventions and takes into consideration my notes above.

    RegDeadline Table
    -----------------
    RegDeadlineID (PK)
    RegistrationID (FK)
    DeadlineDate
    AmountPaid
    InActive


    Registration Table
    -----------------
    RegistrationID (PK)
    Name
    Address
    Email
    Cost
    InActive

    Based on the above database design structure you could execute the following query to get your results.
    Code:
    SELECT A.Name,
    A.Address,
    A.Email,
    B.AmountPaid
    FROM dbo.Registration As A
    INNER JOIN dbo.RegDeadline As B On (A.RegistrationID = B.RegistrationID)
    WHERE DateDiff(day, DeadlineDate, GetDate()) > 1
    AND A.InActive = -1 (Get only Active Records)
    AND B.InActive = -1 (Get only Active Records) 
    Last edited by Memnoch; February 11th, 2009 at 02:19 PM.
    Being educated does not make you intelligent.

  5. #5
    Barn Loyal todd2006 is an unknown quantity at this point todd2006's Avatar
    Join Date
    Mar 2008
    Posts
    889
    Rep Power
    4

    Memnoch,

    thanks for your reply.

    What I am trying to do is make it automated so no manual interaction.

    IT should happen on the server at 1am the next day

    SO the best route is to create a sql report which will include the query or stored procedure and then schedule it.

    is this a right way to go and solve this issue

  6. #6
    Barn Newbie Memnoch will become famous soon enough Memnoch's Avatar
    Join Date
    Nov 2008
    Location
    Missouri
    Posts
    38
    Blog Entries
    1
    Rep Power
    4

    You could do one of the following:

    1) Create the sql as a stored procedure, then write a simple console application that connects to the database and executes the procedure. The setup the console app up as a scheduled task and schedule it to kickoff at 1:00 AM every day.

    OR

    2) Create a new SQL job and schedule it that way.

    #2 is preferred as the least amount of steps possible reduces the risk of some chain in the process breaking.
    Last edited by Memnoch; February 11th, 2009 at 02:22 PM.
    Being educated does not make you intelligent.

+ Reply to Thread

Similar Threads

  1. stored procedure
    By todd2006 in forum ASP Development
    Replies: 7
    Last Post: February 5th, 2009, 03:02 PM
  2. stored procedure
    By todd2006 in forum Microsoft SQL Server
    Replies: 1
    Last Post: February 5th, 2009, 01:25 PM
  3. Using Parameterized Stored Procedure
    By richyrich in forum MySQL
    Replies: 14
    Last Post: June 12th, 2008, 08:00 AM
  4. If statement stored procedure
    By peebman2000 in forum SQL Development
    Replies: 32
    Last Post: May 23rd, 2008, 04:54 PM
  5. Dynamic Stored Procedure
    By jmurrayhead in forum Microsoft SQL Server
    Replies: 16
    Last Post: March 26th, 2008, 12:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO