T-SQL Case Statement in a JOIN ON Clause

后端 未结 6 1999
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 15:09

I am trying to build a case/if statement in a JOIN ON clause.

LEFT JOIN [CTSTRC] [Statuses] ON RIGHT([Statuses].[STRID], 3) = [CTE].[F61]
         


        
6条回答
  •  悲哀的现实
    2021-01-12 15:24

    You're looking for the ISNUMERIC function (I believe it was introduced in SQL 2005):

    LEFT JOIN [CTSTRC] [Statuses] ON 
        (CASE ISNUMERIC(RIGHT([Statuses].[STRID], 3)) WHEN 0 THEN 0 ELSE CAST(RIGHT([Statuses].[STRID], 3) AS INT) END) = [CTE].[F61] 
    

提交回复
热议问题