I have 2 table in sql server freetrial and freetrial_backu p, freetrial table contain startdate and enddate when enddate is over it should transfer all data to freetrial_backu p table pls help me(startdate is registrationdat e and enddate is 2days after registrationdat e)
how to move one table data to another table in sql server
Collapse
X
-
There is no MOVE feature as such. You would need two SQL strings. One to copy the selected data, and another to delete it from the source.
Code:INSERT INTO [FreeTrial_Backup] SELECT * FROM [FreeTrial] WHERE DateAdd(day, 2, [RegistrationDate]) > 2
Code:DELETE FROM [FreeTrial] WHERE DateAdd(day, 2, [RegistrationDate]) > 2
-
That's because I left a very small, but critically important, bit out of the SQL (oops). It should have been comparing it with the current date (GETDATE()) rather than 2.
Code:INSERT INTO [FreeTrial_Backup] SELECT * FROM [FreeTrial] WHERE DateAdd(day, 2, [RegistrationDate]) > GETDATE()
Try that & let us know how it works.Code:DELETE FROM [FreeTrial] WHERE DateAdd(day, 2, [RegistrationDate]) > GETDATE()
Comment
-
thanks 4 reply but it doesnt work i m explaining u what i need:-
table has three column (name, registrationdat e, enddate)
when some one fills form data is inserted in table freetrial
registrationdat e is currentdate when user submits the form and enddate is plus 2days of registrationdat e)
when enddate is over it should MOVE that record to freetrial_backu p table pls help me....Comment
-
Viki,
I'm trying to help, but I can only work within the information provided.
Firstly, there is no good reason to store [EndDate] if it is simply [RegistrationDat e] + 2 days. See Normalisation and Table structures for a full explanation of this.
From what you've told me so far, the value returned by DateAdd(day, 2, [RegistrationDat e]) should be the same as your [EndDate] value anyway. It seems this doesn't work. Unfortunately that's all you've shared. If you could post what happens when you try this. including the code you've used to invoke this SQL and any associated error messages then I will happily give some more consideration to what may be going wrong for you.Comment
-
i have one form.asp page it inserts data in database
in database i have table freetrial and freetrial_backu p
freetrial table has startdate and enddate column (startdate = whn users submits form ) and enddate is plus 2 days of startdate
when enddate is not equal to currentdate it should MOVE the record to freetrial_backu p table i think so it can be done by SQL JOB but i have not extact code 4 it pls help me.....Comment
Comment