Jump to content

Problem changing a fiels from Char to Int


Topshed

Recommended Posts

I am none to good with mysql so here goes

 

I have an Char field length 5 , which I need to convert to an Integer .

Just changing the type does not work as the code does not recognise a number from that field unless I go into edit mode and save the record again which fixes it.

 

My question is is there a Replace command or similar to change the Field type CONTENT from char to integer, or perhaps Creating another field and copying the ex text field into the new field to make that field an interger .  My thinking is I then delete the original field and rename the replacement to the original  ???

 

I do hope that someone with the expertise  can help,

Regards

Roy...

 

 

 

Link to comment
Share on other sites

The people who have altered a column to be an INT type generally don't have any problem. Perhaps you have something like leading spaces or leading zeros in the existing data.

 

To manually do this, backup your database (in case anything goes wrong.) Add a new column of type INT. Execute a single UPDATE query (without a WHERE clause so it will operate on all rows in the table) to set the new column from the existing column values. Confirm your data works. Delete the old column.

 

UPDATE your_table SET new_column = old_column

Link to comment
Share on other sites

Thank you for the reply,

You were correct, there was nothing wrong with my table, the problem was in the documentation.

Working from a pdf document I found

 
’column_name1’ ,"", ’column_name2’ 

rather than 

'column_name1',"",'column_name2'	 

I cannot exactly reproduce the pdf single quote on my keyboard

but the php code did not throw any errors just did not find the data ??

Very strange

 

Regards

Roy

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.