Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Istruzione Case in SQL utilizzando Like

Per prima cosa, aggiornerei il tuo SQL a questo, quindi stai usando un JOIN sul tuo SELECT istruzione invece di inserirla in un WHERE clausola.

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
INNER JOIN Foundation.TaxLiability.EmpowerCalendarCode EmpowerCalendarCode
    ON SystemTax.EmpowerTaxCode = EmpowerCalendarCode.LongAgencyCode 
    AND SystemTax.EmpowerTaxType = EmpowerCalendarCode.EmpowerTaxType

due, cosa succede se rimuovi INSERT INTO ?