Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a store procedure in SQL?

Status
Not open for further replies.

luckyguy

Programmer
Nov 22, 2002
8
MY
Im going to create a DELETE AND UPDATE store procedure in SQL to delete a service agreement from the table based on the expiry date.can someone teach me how?thankx...
 
something like this

CREATE PROCEDURE [sp_yourspname]
as
delete from yourtable where expirydate<getdate()

GO

obviously you need to think about other tables that might store information about the same service agreement. you can script many deletes/updates etc in the same sp

Also do you really need to delete it??? isnt it best just to just create a query to only select non-expired agreements as you may want to revive the record by updating the expiry date

HTH

Andy
 
But the point is my table do not hav a field call expiry date.It only have date Purchasedate ,month existance ,and duration only...!i do not nkow how to write the statements...!need for urgent!thankc....
 
sounds like you should be able to construct a suitable where clause

e.g. where (purchasedate+duration)<getdate()
(getdate() is the current date, dates are really numbers and thus you can do maths with them as shown)

Can you supply some example data of what is valid and what isnt

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top