Jump to content

fieldtype decimal empty if no value...


glennn.php

Recommended Posts

i'm not quite up on when to apply NULL and when not to, and i really want my decimal (5,2) fields to show NO value if there's not an actual value - when i ran a large sql INSERT all my empty fields were converted to '0.00' and phpmyadmin won't let me delete those values...

 

won't decimal allow empty fields?

Link to comment
Share on other sites

"Warning: #1366 Incorrect decimal value: 'NULL' for column 'P-15' at row 1"

 

is decimal(5,2) the reason? perhaps there's a better setting for this fieldtype? i spose i could just set it to varchar (11) and be done with it...?

 

 

Try to update the field and set it's value explicit to NULL

Link to comment
Share on other sites

Make sure you set them to NULL not 'NULL', as the one with quotes is recognised as a string value.

In phpMyAdmin's edit form you have a special checkbox to mark field as NULL. You don't enter the word NULL into value box.

Link to comment
Share on other sites

Make sure you set them to NULL not 'NULL', as the one with quotes is recognised as a string value.

In phpMyAdmin's edit form you have a special checkbox to mark field as NULL. You don't enter the word NULL into value box.

 

i've overlooked that checkbox for i dunno how long... thanks - i only have about fields that are 0.00 -

 

is there an UPDATE table SET ''any field" = NULL where "any field" = '0.00'; ?

 

thanks for your help.

 

G

Link to comment
Share on other sites

It should be:

UPDATE table SET `any field` = NULL where `any field` = 0; 

 

BTW: you're not actually using spaces in field names, do you?

 

:o) - no, 'any field' meant 'any field throughout the table' instead of SET 'field_name' = NULL - i'm looking for a wildcard for all the fields, because the only ones that contain 0.00 would be the ones i don't want in there.

 

what happened is i converted an excel file to an sql file and the query turned all the empty fields into 0.00 where i had it set to decimal. i'd rather not reconvert the entire thing again.

Link to comment
Share on other sites

Actually, if there are many columns, you can use PHP to help you with this.

 

Use

SELECT 
  COLUMN_NAME 
FROM 
  information_schema.columns 
WHERE 
  TABLE_SCHEMA = 'yourDatabase'
  AND TABLE_NAME = 'yourTable'
  AND DATA_TYPE = 'decimal'
  AND IS_NULLABLE = 'YES'

to get list of DECIMAL fields in this table, that can be set to null. Having that, you can write PHP script, that will update all of them the way you like.

Link to comment
Share on other sites

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.