webmaster1 Posted April 21, 2009 Share Posted April 21, 2009 Hi All, I'm using a basic select query puts in a default value if null is returned: SELECT masterdataid, IFNULL(resultsnotations.prospectrating, 'Not Rated') AS prospectratingch, IFNULL(resultsnotations.lastactivity, 'Loaded') AS lastactivity FROM resultsnotations WHERE masterdataid = '339' and prospectrating is null ORDER BY resultsnotations.lastactivity DESC For some reason when I output the row the default value doesn't show. Furthermore when I query for rows will null I can't find any. Am I confusing terminologies here? Is there a difference between NULL and BLANK? Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/ Share on other sites More sharing options...
webmaster1 Posted April 21, 2009 Author Share Posted April 21, 2009 I think what I'm asking is what's the difference between '' and NULL and how should work this into the IFNULL. Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815901 Share on other sites More sharing options...
soak Posted April 21, 2009 Share Posted April 21, 2009 and (prospectrating is null OR prospectrating = '') That what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815902 Share on other sites More sharing options...
webmaster1 Posted April 21, 2009 Author Share Posted April 21, 2009 and (prospectrating is null OR prospectrating = '') That what you mean? That's exactly it. Any idea's how to work this into the IFNULL condition I'm using? Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815904 Share on other sites More sharing options...
soak Posted April 21, 2009 Share Posted April 21, 2009 exactly as typed: SELECT masterdataid, IFNULL(resultsnotations.prospectrating, 'Not Rated') AS prospectratingch, IFNULL(resultsnotations.lastactivity, 'Loaded') AS lastactivity FROM resultsnotations WHERE masterdataid = '339' and (prospectrating is null OR prospectrating = '') ORDER BY resultsnotations.lastactivity DESC Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815909 Share on other sites More sharing options...
webmaster1 Posted April 21, 2009 Author Share Posted April 21, 2009 I want to apply it here: IFNULL(resultsnotations.prospectrating, 'Not Rated') AS prospectratingch and not at the WHERE part. Example: If prospectrating is null or blank then its default value is 'not rated'. Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815912 Share on other sites More sharing options...
nankoweap Posted April 21, 2009 Share Posted April 21, 2009 null and the empty string are two totally different things. null is essentially undefined, not set, nothing, etc. the empty string is something - it's a string with a length of zero. Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815913 Share on other sites More sharing options...
webmaster1 Posted April 21, 2009 Author Share Posted April 21, 2009 null and the empty string are two totally different things. null is essentially undefined, not set, nothing, etc. the empty string is something - it's a string with a length of zero. Thanks for the run-through. Any ideas on how I check for string length using the IFNULL as well? Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815916 Share on other sites More sharing options...
nankoweap Posted April 21, 2009 Share Posted April 21, 2009 look into using case rather than ifnull in your query... http://dev.mysql.com/doc/refman/6.0/en/control-flow-functions.html that should do the trick. jason Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815920 Share on other sites More sharing options...
soak Posted April 21, 2009 Share Posted April 21, 2009 Beat me to it nankoweap Ahhh, apologies, don't know how I missed those. You could use a case. Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815922 Share on other sites More sharing options...
webmaster1 Posted April 21, 2009 Author Share Posted April 21, 2009 I've read through both links though I still don't understand. Could someone dumb this down for me a little more? Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815932 Share on other sites More sharing options...
webmaster1 Posted April 21, 2009 Author Share Posted April 21, 2009 Yep, still not making any sense of this. All I need is to check if string blank as well as if null. Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815962 Share on other sites More sharing options...
soak Posted April 21, 2009 Share Posted April 21, 2009 SELECT CASE `field` WHEN '' THEN 'Value' ELSE IFNULL( `field` , 'Value' ) END FROM `table` Quote Link to comment https://forums.phpfreaks.com/topic/155106-quickie-null-versus-blank/#findComment-815999 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.