0

所以我有两个使用相同计算的列别名:

,case when bi.PolicyFeeFactor = 0 then 0 else CAST(ROUND(nb.AnnualPolicyFee * bi.PolicyFeeFactor,2)AS DECIMAL(6,2)) end as UNIT_POLFEE_Y

,case when bi.PolicyFeeFactor = 0 then 0 else CAST(ROUND(nb.AnnualPolicyFee * bi.PolicyFeeFactor,2)AS DECIMAL(6,2)) end as UNIT_PUPFEE_Y

我正在寻找一种方法,我可以只编写一次计算并从该语句创建两个列别名,例如:

,case when bi.PolicyFeeFactor = 0 then 0 else CAST(ROUND(nb.AnnualPolicyFee * bi.PolicyFeeFactor,2)AS DECIMAL(6,2)) end as UNIT_PUPFEE_Y, UNIT_POLFEE_Y

4

2 回答 2

0

将其包装在子查询中,例如

SELECT Result AS UNIT_PUPFEE_Y, 
       Result AS UNIT_POLFEE_Y
FROM
    (
        SELECT CASE .... END AS Result
        FROM   tableName
    ) s
于 2013-03-28T10:33:56.523 回答
0

你可以这样写,

SELECT *,UNIT_PULFEE_Y AS UNIT_PUPFEE_Y FROM
(SELECT *
,case when bi.PolicyFeeFactor = 0 then 0 else CAST(ROUND(nb.AnnualPolicyFee *              bi.PolicyFeeFactor,2)AS DECIMAL(6,2)) end as UNIT_PULFEE_Y
FROM Table )A
于 2013-03-28T10:39:34.193 回答