christopher clark christopher clark - 25 days ago 6
SQL Question

Is there a way to ignore the AND in a CASE when something is true?

I have this

Where
clause

Select * From Student_Info si
Inner Join Certifications cc
Inner Join Cert_Earned ce

Where si.grad_date = @grad_date
AND cc.org_no = @org_no


but I need an additional
AND
that should be ignored if it turns out the value is false, I will want ALL certificates

AND cc.industrial = CASE WHEN @industrial = 0 THEN Do Nothing
Else @industrial

Answer

This would normally be expressed as:

AND (@industrial = 0 OR ccc.industrial = @industrial)