为同一列中的两个输出值评估相同的条件

时间:2021-06-30 13:17:31

How to evaluate the same condition for two different outputs. for example:

如何评估两种不同输出的相同条件。例如:

select case
          when 1 = 1 and 2 = 2 then 'one'
          when 1 = 1 and 2 = 2 then 'Two'
       end

how to make this statement to be executed for two times. rest of the columns have the same data. I tried in a couple of ways but did not have luck. Thank you.

如何使这个语句执行两次。其余列具有相同的数据。我尝试了几种但没有运气。谢谢。

1 个解决方案

#1


1  

As i understand, you want to use complex condition more the one time -

据我所知,你想一次性使用复杂的条件 -

You can implement this by storing the result within OUTER APPLY (Or CROSS APPLY) field

您可以通过将结果存储在OUTER APPLY(或CROSS APPLY)字段中来实现此目的

Like this:

select case when condition.is_true = 1
            then 'one'
            else null
       end as one,
       case when condition.is_true = 1
            then 'two'
            else null
       end as two
from table_name
outer apply
(
    select case when 1 = 1 and 2 = 2
                then 1
                else 0
           end as is_true
)condition

#1


1  

As i understand, you want to use complex condition more the one time -

据我所知,你想一次性使用复杂的条件 -

You can implement this by storing the result within OUTER APPLY (Or CROSS APPLY) field

您可以通过将结果存储在OUTER APPLY(或CROSS APPLY)字段中来实现此目的

Like this:

select case when condition.is_true = 1
            then 'one'
            else null
       end as one,
       case when condition.is_true = 1
            then 'two'
            else null
       end as two
from table_name
outer apply
(
    select case when 1 = 1 and 2 = 2
                then 1
                else 0
           end as is_true
)condition