Jump to content

[SOLVED] Update question


jim.davidson

Recommended Posts

I have a table with 3 fields

field1 is an int

field2 is an int

field3 is an varchar

 

I need to take the values from  fields 1 and 2, combine them and put the result in field3.

 

Example field1 = 4567

            field2 = 2345

            field3 = "45672345"

 

How would I write the update command?

Link to comment
https://forums.phpfreaks.com/topic/45762-solved-update-question/
Share on other sites

Look in the MySQL manual, chapter 12 on functions, specifically the LPAD() and CONCAT() functions.

 

UPDATE table_name SET field3=CONCAT(LPAD(field1,4,'0'),LPAD(field2,4,'0'));

 

From your example I've assumed that you have four digit numbers and want an eight character string.  If you want something different, you can probably find functions to fit your needs.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.