您好我有一条SQL语句
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
尽管CalendarName的值类似于季度(EOM),但我仍然得到0.任何想法和建议!
答案 0 :(得分:9)
首先,我会将您的SQL更新为此,因此您在JOIN
语句中使用SELECT
而不是将其放在WHERE
子句中。
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
二,如果您删除INSERT INTO
会怎样?
答案 1 :(得分:1)
您也可以这样做。我认为这会起作用。
select *
from table
where columnName like '%' + case when @varColumn is null then '' else @varColumn end + ' %'
答案 2 :(得分:0)
尝试使用UPPER()排除任何区分大小写的问题:
CASE WHEN(isnull(EmpowerCalendarCode.CalendarName,'none'))LIKE'%MONTHLY%'那么3 ...