我正在尝试将if语句转换为SQL case语句,并且没有太多运气让逻辑正常工作。 (我的问题是SQL case statement in a stored procedure
的更新版本if LossStatusCode == 'R' Then 'Item has been reviewed.'
ELseif //if LossStatusCode != 'R'
DateOfLoss < PolicyStartDate THEN 'Invalid Date'
MilesDriven > TotalMilesAllowed THEN 'Mileage exceeded'
Else // if (LossStatusCode != 'R') && Date is valid && Mileage is Valid)
LossStatusCode != 'R' Then 'Status code is Review.'
如何将上述逻辑转换为SQL Case语句?
答案 0 :(得分:2)
select case when LossStatusCode = 'R' then 'Item has been reviewed.'
when DateOfLoss < PolicyStartDate and MilesDriven > TotalMilesAllowed then 'Invalid Date, Mileage exceeded'
when DateOfLoss < PolicyStartDate then 'Invalid Date'
when MilesDriven > TotalMilesAllowed then 'Mileage exceeded'
else 'Status code is Review.'
end