Connecting Tech Pros Worldwide Help | Site Map

MYSQL 'NULL' cant be replased

prabirchoudhury's Avatar
Familiar Sight
 
Join Date: May 2009
Location: Wellington, New Zealand
Posts: 152
#1: Jul 28 '09
hey all i am having problem with NULL values to replace with, i have been using all the way to replace NULL value but non of those working for me. NOT NULL field is replacing with abut not the NULL field. i have tested the conditions to replace NULL in other simple query those are working but not the code bellow.
i have tryed with

Expand|Select|Wrap|Line Numbers
  1. 1. if((field IS NULL), 'XX', field) 
  2. 2. ISNULL(field),'XX',field 
  3. 3. CASE WHEN field IS NULL then 'XX' else field end 
  4. 4. IF(field IS NULL,'XX',field) 
  5.  
  6.  
my origunal code down here, please any one could help.

Expand|Select|Wrap|Line Numbers
  1.  
  2. select DISTINCT d.title, d.schemecode, d.objectives, 
  3. d.eligibility, d.eligibledistricts, 
  4. date_format(f.closingdate, '%d/%m/%Y') as closedate, o.type 
  5. ,( select DISTINCT COUNT(cr.CritCode) AS Rank 
  6. from CRITERIA cr 
  7. INNER JOIN SCHCRIT sc on sc.CritCode=cr.CritCode 
  8. where sc.SchemeCode= a.schemecode 
  9. AND cr.CritCode in(71,5043, 5074, 5024, 5025, 4003, 0)) AS match_rank 
  10. ,(select IF(Description IS NULL,'XX',Description) 
  11. from CRITERIA cr 
  12. INNER JOIN SCHCRIT sc on sc.CritCode=cr.CritCode where sc.SchemeCode= a.schemecode 
  13. AND cr.CritCode = 4003) AS cost1 
  14.  
  15. FROM SCHCRIT a inner join SCHCRIT b on(a.schemecode=b.schemecode) 
  16. inner join SCHCRIT c on(a.schemecode=c.schemecode) 
  17. inner join SCHEMES d on(a.schemecode=d.schemecode) 
  18. inner join PROTECTS e on(d.protectlevel=e.protectlevel) 
  19. inner join SCHORD f on(a.schemecode=f.schemecode) 
  20. inner join personOrganisation po on (d.sourceorg=po.personid) 
  21. inner join organisation o on(po.organisationid=o.organisationid) 
  22. WHERE (a.critcode =1 or a.critcode =71) 
  23. and c.critcode in (4000, 4003, 0, 0, 0) 
  24. and b.critcode in (5000, 5043, 5074, 5024, 5025) 
  25. and e.searchresults = 'T' order by match_rank DESC, cost1 ASC
  26.  
  27.  
thanks in advanced
:)
Member
 
Join Date: Feb 2009
Posts: 57
#2: Jul 28 '09

re: MYSQL 'NULL' cant be replased


You can try with
Expand|Select|Wrap|Line Numbers
  1. IFNULL(<field_name>,Value)
If the field is null then it will replace it with the given value.

Thanks,
Lauren
prabirchoudhury's Avatar
Familiar Sight
 
Join Date: May 2009
Location: Wellington, New Zealand
Posts: 152
#3: Jul 28 '09

re: MYSQL 'NULL' cant be replased


thanks for your reply...
the problem is not with the
Quote:
IFNULL(<field_name>,Value)
IFNULL() or IF() function to replace the NULL value but when i add this function with subquery then it wont work, my main query is working fine itself and when i added the subquery that work fine , but i wanted to sort on this subquery return but, subquery fetches with null values those comes on top with " ORDER BY ASC" sort, so wanted to put all null values on the end os the sorting .. when i am trying to replace NULL using those functions then it doesn’t replace NULL,
Expand|Select|Wrap|Line Numbers
  1. This my sub query
  2. ,(select IF(Description IS NULL,'XX',Description)  
  3. from CRITERIA cr  
  4. INNER JOIN SCHCRIT sc on sc.CritCode=cr.CritCode where sc.SchemeCode= a.schemecode  
  5. AND cr.CritCode = 4003) AS cost1  
  6.  

thanks, prabir
Reply

Tags
isnull, mysql, notnull, null, null value