DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

SQL Job or stored procedure

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 ...

Go Back   DeveloperBarn Forums > Databases > SQL Development

  #1  
Old February 10th, 2009, 11:16 PM
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 463
Rep Power: 2
todd2006 is an unknown quantity at this point
Default 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
Reply With Quote
  #2  
Old February 11th, 2009, 01:46 AM
Memnoch's Avatar
Moderator from Hell
 
Join Date: Nov 2008
Location: Missouri
Posts: 26
Blog Entries: 1
Rep Power: 2
Memnoch will become famous soon enough
Default

Are there keys linking the two tables together? If so, which ones?
__________________
Being educated does not make you intelligent.
Reply With Quote
  #3  
Old February 11th, 2009, 10:02 AM
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 463
Rep Power: 2
todd2006 is an unknown quantity at this point
Default

Hello,

Id is the primary key in Registration_deadline table and Reg_Id is the foreign key in the Registration table.
Reply With Quote
  #4  
Old February 11th, 2009, 01:00 PM
Memnoch's Avatar
Moderator from Hell
 
Join Date: Nov 2008
Location: Missouri
Posts: 26
Blog Entries: 1
Rep Power: 2
Memnoch will become famous soon enough
Default

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.
Reply With Quote
  #5  
Old February 11th, 2009, 01:15 PM
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 463
Rep Power: 2
todd2006 is an unknown quantity at this point
Default

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
Reply With Quote
  #6  
Old February 11th, 2009, 02:20 PM
Memnoch's Avatar
Moderator from Hell
 
Join Date: Nov 2008
Location: Missouri
Posts: 26
Blog Entries: 1
Rep Power: 2
Memnoch will become famous soon enough
Default

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.
Reply With Quote
Reply

  DeveloperBarn Forums > Databases > SQL Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

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


All times are GMT -4. The time now is 11:17 PM.


Copyright ©2008-2010, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2