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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete data more then 7 days old

Status
Not open for further replies.

Niklos

Technical User
Sep 14, 2008
1
DK

Hi

I need some help with a script

I want to delete users from the users table where the customgroup contains 'P', but only those users then 7 days old, and the day where the users was entered are stored in a table call extrafield in the colum extra10 in this format
dd-mm-yyyy

i made this script

delete from users where customgroup='P' and userid in(Select userid from EXTRAFIELD where((@now-@date(@int(@substring(EXTRA10,6,4)), @int(@substring(EXTRA10,3,2)), @int(@left(EXTRA10,2)))>=7)));

but it gives me a 00318 error

Can anyone help me to make a script that works

Regards

Niklos


 

No doubt you had your reasons for using a Char column to store date values, and also to use such meaningless colum names.
Either convert the EXTRA10 column to Date/Time, so you can compare directly to SYSDATE or try:

Delete from users
where customgroup='P' and
userid in(Select userid from EXTRAFIELD
where @DATE( @SUBSTRING( EXTRA10 ,6,4), @SUBSTRING( EXTRA10 ,3,2),@SUBSTRING( EXTRA10 ,0,2) ) < SYSDATE - 7;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top