October 28, 2009 at 8:00 am
Hello friends can someone get me a stored procedure to delete some data from a table if we give a particular date in the parameter. anything is ok.
October 28, 2009 at 8:11 am
umm thats fairly generic...
create procedure USP_DeleteMyData
@date datetime
as
Delete from MyTable where MyDate = @date
go
October 28, 2009 at 8:13 am
no that does not work
October 28, 2009 at 8:16 am
Take this and move it to a procedure:
DECLARE
@table VARCHAR(100)
,@date VARCHAR(30)
,@sql VARCHAR(1000);
SELECT
@table = 'mytable'
,@date = '1901-01-01';
SELECT
@sql = 'DELETE FROM ' + @table + ' WHERE AnyColumn < ''' + @date + '''';
PRINT (@sql);
-- EXECUTE (@sql);
Greets
Flo
October 28, 2009 at 8:18 am
so where should be the create procedure statement be. sorry for that but i i totally blank.
October 28, 2009 at 8:33 am
espanolanthony (10/28/2009)
no that does not work
what do you mean it doesnt work??
i assume you replaced the MyTable with your tablename?
October 28, 2009 at 8:36 am
espanolanthony (10/28/2009)
so where should be the create procedure statement be. sorry for that but i i totally blank.
Look at CREATE PROCEDURE in Books On Line (BOL)
October 28, 2009 at 8:38 am
Hi
I really don't think it makes sense that you just get any statements from here you don't understand. Please have a look to CREATE PROCEDURE. You really should know what you are doing (especially if you want to manipulate data).
Greets
Flo
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply