Jump to content

IFNULL returning NULL


Adamhumbug

Recommended Posts

Hi All,

I have the following, and when i run it the ifnull() is returning null rather than 0 as shown in the attached.

Any help on this would be greatly appreciated.

select *
from 
( SELECT ptsl_ptd_id, SUBSTRING(ptsl_date,1,10) as ptsl_date, ptsl_z_id, z_rfid, ptsl_limit 
	FROM `prs_ptsl` 
	inner join prs_z on ptsl_z_id=z_id 
	where ptsl_ptd_id='7' 
) as limits 
left join 
( SELECT pr_ptd_id, za_sdate, za_z_id, za_z_rfid, IFNULL(count(za_pr_id), 0)
	as used 
	FROM `prs_za` 
	inner join prs_pr on za_pr_id=pr_id 
        where prs_pr.pr_status = 'Approved' or prs_pr.pr_status = 'Submitted'
	group by za_sdate, za_z_id, za_z_rfid 
	) 
as used 
on limits.ptsl_ptd_id=used.pr_ptd_id 
and limits.ptsl_date=used.za_sdate 
and ptsl_z_id=za_z_id 
where ptsl_date = '2021-06-12' and (ptsl_limit - IFNULL(used, 0) >= 0)
limit 100

 

Screenshot 2021-03-12 at 16.02.39.png

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.