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

Can I know the issue of this SQL query

I have this SQL query:

enter image description here

but I’m getting an error:

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

enter image description here

If I remove the comma-separated value from the variable, it is working fine. As well as if I remove the NULL checking feature it is working fine. Can I know the issue of this

>Solution :

It’s because a CASE WHEN can only return 1 value.
And a STRING_SPLIT returns a resultset.

I assume something like this is what you want.

SELECT *
FROM Facility f
WHERE (@Facility IS NULL OR f.facilityCode IN (SELECT value FROM string_split(@Facility,','))) 

This will get all records if the variable is null.

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