Click to See Complete Forum and Search --> : Need to move values from one field to another in same table


scaiferw
07-01-2006, 02:44 PM
I have a table of service clubs with fields I'll call vice_president, president_elect, president, past_president

With the change in operating year, each needs to move to the next, i.e. for each club in the table;

vice_president becomes president_elect
president_elect becomes president
president becomes past_president
(vice_president is left blank.)

Existing values should be over-written.

All fields are VARCHAR(50).

Google and the books I have aren't telling me anything helpful, which probably means I'm being a little bit dense today.

Also, can this be chained together into one statement that I could run on a cron job or something like that at midnight of the changeover day?

Can anyone tell me how to do this?

Many thanks,

Rob

NogDog
07-01-2006, 03:14 PM
Could you just run this one query?

UPDATE table_name
SET past_president = president,
president = president_elect,
president_elect = vice_president,
vice_president = '';

scaiferw
07-01-2006, 03:39 PM
Thank you NogDog, after I posted that I thought perhaps I was over-engineering the process and that it was a little more basic than I thought.

The following worked like a charm in testing;
update clubs set ppfname=presfname,pplname=preslname,ppemail=presemail;
update clubs set presfname=pefname,preslname=pelname,preseemail=peemail;
update clubs set pefname=vpfname,pelname=vplname,peemail=vpemail;
update clubs set vpfname="",vplname="",vpemail="";
So I came back here to report my success and saw you reply.

My two remaining questions are these;

1. Can I chain these together so that I can run them all as a single statement?

2. Is there typically a way to have the query run and to this at 12:01 am on a specific day?

Many thanks for your help,

Rob