glennn.php Posted March 29, 2010 Share Posted March 29, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/ Share on other sites More sharing options...
ignace Posted March 29, 2010 Share Posted March 29, 2010 That is because your decimal field currently has NOT NULL change it to NULL that way it allows you to have NULL as a value Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033722 Share on other sites More sharing options...
glennn.php Posted March 29, 2010 Author Share Posted March 29, 2010 they're ALL NULL already - when i try to delete the fields with 0.00 the error is "#1366 Incorrect decimal value: '' for column 'P-15' at row 1" (it's set to decimal(5,2)) Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033737 Share on other sites More sharing options...
fenway Posted March 29, 2010 Share Posted March 29, 2010 Then check the actual value. Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033748 Share on other sites More sharing options...
ignace Posted March 29, 2010 Share Posted March 29, 2010 Try to update the field and set it's value explicit to NULL Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033753 Share on other sites More sharing options...
glennn.php Posted March 29, 2010 Author Share Posted March 29, 2010 "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 Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033758 Share on other sites More sharing options...
Mchl Posted March 29, 2010 Share Posted March 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033814 Share on other sites More sharing options...
glennn.php Posted March 29, 2010 Author Share Posted March 29, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033822 Share on other sites More sharing options...
Mchl Posted March 29, 2010 Share Posted March 29, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033827 Share on other sites More sharing options...
glennn.php Posted March 29, 2010 Author Share Posted March 29, 2010 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? ) - 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. Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033829 Share on other sites More sharing options...
Mchl Posted March 29, 2010 Share Posted March 29, 2010 No, there's no field wildcard because usually you don't need anything like it. Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033837 Share on other sites More sharing options...
glennn.php Posted March 29, 2010 Author Share Posted March 29, 2010 No, there's no field wildcard because usually you don't need anything like it. didn't think so - i'll just do it column by column then. thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033838 Share on other sites More sharing options...
Mchl Posted March 29, 2010 Share Posted March 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196884-fieldtype-decimal-empty-if-no-value/#findComment-1033842 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.