PDA

View Full Version : Copy records with new date in the same table



kunguito
10-23-2008, 01:23 AM
I want to copy all records (preserving the old ones) from a certain date (a combination of month and year) with a new date.

Here's what i've worked out.


INSERT INTO TABLE ( Field1, Field2,Field3, Month, Year)
SELECT TABLE.Field1, TABLE.Field2, TABLE.Field3 FROM TABLE
WHERE (((TABLE.Month)=[OldMonth]) AND ((TABLE.Year)=[OldYear]));


But obviously I'm not feeding in the new month values.

CreganTur
10-23-2008, 09:23 AM
Are you saying that you want to update all records with a specified date with a new date? If so they you want to use the following Syntax:
UPDATE Table SET Table.FieldName = DesiredResult

You can add in WHERE clauses as usual, along with anything else you may need.

Solo_TA
10-30-2008, 04:56 AM
You are very close. I would use following command:
INSERT INTO TABLE ( Field1, Field2,Field3, Month, Year)
SELECT TABLE.Field1, TABLE.Field2, TABLE.Field3, NewMonth, Newyear
FROM TABLE WHERE (((TABLE.Month)=[OldMonth]) AND ((TABLE.Year)=[OldYear]));
where NewMonth and NewYear are new date

kunguito
10-30-2008, 08:37 AM
Yeah! Wasn't so difficult, was it?

Thanks dude!