dbTalk Databases Forums  

Update automatically a field in more than one record

comp.databases.mysql comp.databases.mysql


Discuss Update automatically a field in more than one record in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Francesco
 
Posts: n/a

Default Update automatically a field in more than one record - 10-12-2010 , 06:18 AM






Hello everybody,

I'm relatively new in database management and programming, and I have
a simple question: I need to update a Date Field in multiple records
in this way: first record's Date field must have a certain date.
Second record must have the previous date plus a week. Third record
must have the date of second record plus a week, and so on.
The question is: is there a way to do this automatically?

Thank You!

Reply With Quote
  #2  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Update automatically a field in more than one record - 10-12-2010 , 11:54 AM






On 2010-10-12 13:18, Francesco wrote:
Quote:
Hello everybody,

I'm relatively new in database management and programming, and I have
a simple question: I need to update a Date Field in multiple records
in this way: first record's Date field must have a certain date.
Second record must have the previous date plus a week. Third record
must have the date of second record plus a week, and so on.
The question is: is there a way to do this automatically?

What does first, second etc. mean, i.e. by what criteria are you
ordering the resultset?

/Lennart

Reply With Quote
  #3  
Old   
Francesco
 
Posts: n/a

Default Re: Update automatically a field in more than one record - 10-13-2010 , 10:23 AM



Quote:
What does first, second etc. mean, i.e. by what criteria are you
ordering the resultset?

/Lennart
i'm ordering the records by ID.
i have a certain number of records. I would cange the date field of
all these records at once.
for example: I have 5 records, ordered by id (first record: ID=1,
second record: ID=2, ecc); all these records have a Date field set:
2010-01-01 00:00:00. So, i would cange Date field in this way: record
1 (ID=1, Date 2010-10-05); record 2: (ID=2, Date 2010-10-12), record
3: (ID=3, Date= 2010-10-19), record 4: (ID=4, Date= 2010-10-26),
etc...
Is there a way to do this using some kind of sintax in MySQL, or I
have to do a script in another language (PHP, ASP, etc)?

Reply With Quote
  #4  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Update automatically a field in more than one record - 10-13-2010 , 09:59 PM



On 2010-10-13 17:23, Francesco wrote:
Quote:
What does first, second etc. mean, i.e. by what criteria are you
ordering the resultset?

/Lennart

i'm ordering the records by ID.
i have a certain number of records. I would cange the date field of
all these records at once.
for example: I have 5 records, ordered by id (first record: ID=1,
second record: ID=2, ecc); all these records have a Date field set:
2010-01-01 00:00:00. So, i would cange Date field in this way: record
1 (ID=1, Date 2010-10-05); record 2: (ID=2, Date 2010-10-12), record
3: (ID=3, Date= 2010-10-19), record 4: (ID=4, Date= 2010-10-26),
etc...
Is there a way to do this using some kind of sintax in MySQL, or I
have to do a script in another language (PHP, ASP, etc)?
Something like:

update t set d = '2010-10-05' + interval (id-1) week;


/Lennart

Reply With Quote
  #5  
Old   
Francesco
 
Posts: n/a

Default Re: Update automatically a field in more than one record - 10-15-2010 , 04:18 AM



Quote:
Something like:

update t set d = '2010-10-05' + interval (id-1) week;

/Lennart
Yes!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.