Can I use CASE statement in a JOIN condition?

前端 未结 9 1775
庸人自扰
庸人自扰 2020-11-22 09:32

The following image is a part of Microsoft SQL Server 2008 R2 System Views. From the image we can see that the relationship between sys.partitions and sys

9条回答
  •  一生所求
    2020-11-22 09:45

    Yes, you can. Here is an example.

    SELECT a.*
    FROM TableA a
    LEFT OUTER JOIN TableB j1 ON  (CASE WHEN LEN(COALESCE(a.NoBatiment, '')) = 3 
                                    THEN RTRIM(a.NoBatiment) + '0' 
                                    ELSE a.NoBatiment END ) = j1.ColumnName 
    

提交回复
热议问题