# Stored procedure not filtering

**URL:** https://forum.codewithmosh.com/t/stored-procedure-not-filtering/16818
**Category:** SQL
**Created:** [December 2, 2022, 10:16am UTC](https://forum.codewithmosh.com/t/stored-procedure-not-filtering/16818 "2022-12-02T10:16:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Martins](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Martins](https://forum.codewithmosh.com/u/Martins)
#### Post date: [December 2, 2022, 10:16am UTC](https://forum.codewithmosh.com/t/stored-procedure-not-filtering/16818/1 "2022-12-02T10:16:43Z")

</div>

This stored procedure is not filtering when called up, I will appreciate any advice:

USE invoicing;  
DELIMITER //  
CREATE PROCEDURE get\_payments(client\_id INT, payment\_method\_id TINYINT)  
BEGIN  
SELECT \*  
FROM payments p  
WHERE  
p.client\_id = IFNULL(client\_id, p.client\_id) AND  
p.payment\_method = IFNULL(payment\_method, p.payment\_method);  
END //  
DELIMITER ;

CALL get\_payments(5,2);

---

<div class="post-metadata">

### Author: ![keelo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/keelo/32/4592_2.png) [@keelo](https://forum.codewithmosh.com/u/keelo)
#### Post date: [December 2, 2022, 7:32pm UTC](https://forum.codewithmosh.com/t/stored-procedure-not-filtering/16818/2 "2022-12-02T19:32:10Z")

</div>

Are you using Mosh’s SQL course material?  
If you are there is a slight error in your script.  
The database ‘invoicing’ doesn’t exists  
Try changing:

USE invoicing;  
to  
USE sql\_invoicing

Hope this helps

---

<div class="post-metadata">

### Author: ![Martins](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Martins](https://forum.codewithmosh.com/u/Martins)
#### Post date: [December 2, 2022, 7:58pm UTC](https://forum.codewithmosh.com/t/stored-procedure-not-filtering/16818/3 "2022-12-02T19:58:47Z")

</div>

its basically the same database. same tables

---

<div class="post-metadata">

### Author: ![Martins](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Martins](https://forum.codewithmosh.com/u/Martins)
#### Post date: [December 3, 2022, 5:30am UTC](https://forum.codewithmosh.com/t/stored-procedure-not-filtering/16818/4 "2022-12-03T05:30:49Z")

</div>

Thanks a lot. I have seen the issue.
