Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Delete records in a table using stored procedure

Author  Topic 

Firetubes
Starting Member

2 Posts

Posted - 2006-02-26 : 07:39:47
Hi, I would like to delete some records in a table older than a specified date using a stored procedure. Can anyone help?
Thank you,
Cynthia

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-02-26 : 09:18:23
first of all, post what sql statements you have...

it is always better to work with something or you may search the sticky post by Kristen

HTH

--------------------
keeping it simple...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-26 : 09:41:11
[code]
create procedures some_procedure
@somedate datetime
as
begin
delete yourtable
where somedatecol < @somedate
end
[/code]

----------------------------------
'KH'

It is inevitable
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-27 : 00:50:04
I prefer using

where somedatecol < DateAdd(day,DateDiff(day,0,@somedate),0)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Firetubes
Starting Member

2 Posts

Posted - 2006-02-27 : 18:17:31
Thank you for the help! My first stored procedure works. I didn't use the date column but I think I'm on the right track.

If my somedatecol is actually a text string with the format 'yy/mm/dd hh:mm:ss', how can I convert this over to check for the date?

Regards,
Cynthia
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-27 : 20:04:56
You should use proper data type. if your somedatecol is a char or varchar, change it to datetime or smalldatetime.
You can use convert() to convert from string to datetime.

----------------------------------
'KH'


Go to Top of Page
   

- Advertisement -