IF
用于流量控制。对于表达式,只需使用
CASE
:
Insert Into IanaTable (IanaTimezone)
Select
case
when CONDITION1 then RESULT1
when CONDITION2 then RESULT2
......
when CONDITION100 the RESULT100
end as IanaTimezone
From WindowsTzTable
编辑:由于OP表示他们更喜欢一个函数,因为相同的值将分配给多个列,所以我反对使用横向连接来别名表达式。这是更好的,因为即使是复制粘贴函数名也是湿的,而且容易出错。在这里:
Insert Into IanaTable (...)
Select
q1.IanaTimezone as column1
,q1.IanaTimezone as column2
,q1.IanaTimezone as column3
,othervalue as othercolumn
......
From
WindowsTzTable
cross apply
(
Select
case
when CONDITION1 then RESULT1
when CONDITION2 then RESULT2
......
when CONDITION100 the RESULT100
end as IanaTimezone
) as q1