Case Statement in SQL using Like

Viewed 95064

Hello I have a SQL statement

INSERT INTO Foundation.TaxLiability.EmpowerSystemCalendarCode

SELECT SystemTax.SystemTaxID,
       EmpowerCalendarCode.CalendarCodeID
      ,CASE WHEN  EmpowerCalendarCode.CalendarName LIKE '%Monthly%' THEN 3
            WHEN  EmpowerCalendarCode.CalendarName LIKE '%Annual%' THEN 2
            WHEN  EmpowerCalendarCode.CalendarName LIKE '%Quarterly%' THEN 4
       ELSE 0
       END
       FROM Foundation.Common.SystemTax SystemTax, Foundation.TaxLiability.EmpowerCalendarCode EmpowerCalendarCode
WHERE SystemTax.EmpowerTaxCode = EmpowerCalendarCode.LongAgencyCode and SystemTax.EmpowerTaxType = EmpowerCalendarCode.EmpowerTaxType

Even though CalendarName has values like Quarterly (EOM) I still end up getting 0. Any ideas and suggestions!

3 Answers

You can also do like this. I think this will work.

select *
from table
where columnName like '%' + case when @varColumn is null then '' else @varColumn end  +  ' %'
Related