This is a discussion on SQL Job or stored procedure within the SQL Development forums, part of the Databases category; Hi, Can someone guide me in the right direction. I have table called Registration_Deadline design is like this Id Name ...
| |||||||
|
#1
| |||
| |||
| Hi, Can someone guide me in the right direction. I have table called Registration_Deadline design is like this Id Name 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 |
|
#3
| |||
| |||
| Hello, Id is the primary key in Registration_deadline table and Reg_Id is the foreign key in the Registration table. |
|
#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 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. |
|
#5
| |||
| |||
| 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
| ||||
| ||||
| 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. |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| stored procedure | todd2006 | ASP Development | 7 | February 5th, 2009 03:02 PM |
| stored procedure | todd2006 | Microsoft SQL Server | 1 | February 5th, 2009 01:25 PM |
| Using Parameterized Stored Procedure | richyrich | MySQL | 14 | June 12th, 2008 07:00 AM |
| If statement stored procedure | peebman2000 | SQL Development | 32 | May 23rd, 2008 03:54 PM |
| Dynamic Stored Procedure | jmurrayhead | Microsoft SQL Server | 16 | March 26th, 2008 11:19 AM |