SQL Conditional column data return in a select statement

前端 未结 2 670
不知归路
不知归路 2020-12-15 15:23

Here is a simplication of the problem: I have a select that looks like this:

Select ID, Assignee, WorkStream from assignees;

And a snap sho

2条回答
  •  时光取名叫无心
    2020-12-15 16:04

    You didn't mention your DBMS but a searched CASE statement works in all major DBMS's I know off.

    SELECT  ID
            , CASE WHEN WorkStream = 'Internal'
                   THEN WorkStream
                   ELSE Assignee
              END AS Assignee
            , Workstream
    FROM    assignees
    

    Reference: MSDN

    CASE

    Evaluates a list of conditions and returns one of multiple possible result expressions.

提交回复
热议问题