Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fixed SQL Query if paramerter empty also incluce NULL

I’m using the following where condition in a fixed sql query:

and ([NC_DATA].WORK_CENTER_BO LIKE '%[Param.4]%' OR '[Param.4]' IS NULL)

and its working fine when I enter a value for Param.4, but when I don’t use Param.4 it’s not giving the NULL paramter only data with values. How can I achieve that I get data with values and also data = NULL

Thanks for helping!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What I tried:

and ([NC_DATA].WORK_CENTER_BO LIKE '%[Param.4]%' OR '[Param.4]' IS NULL)

I get:

Column 1 WORK_CENTER_BO
ABC 123
DEF 456

I expecting:

Column 1 WORK_CENTER_BO
ABC 123
DEF 456
GHI NULL

>Solution :

You can try using the COALESCE function as follows:

and (COALESCE([NC_DATA].WORK_CENTER_BO, '[Param.4]') LIKE '%[Param.4]%')

If your "WORK_CENTER_BO" is null, it will be replaced with [Param.4] to match the condition.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading