Get the character between first 2 special character in SQL

前端 未结 2 1830
你的背包
你的背包 2020-11-30 14:51

I have data in sql (Just to note: SQL STudio is the IDE) like:

data
a_10_b_c
a_1_b_c

I want to get t

2条回答
  •  被撕碎了的回忆
    2020-11-30 15:22

    You can do this with nested string functions. Often, this is simpler using outer apply:

    select t3.output
    from t outer apply
         (select stuff(t.col, 1, charindex('_', t.col), '') as col2
         ) t2 outer apply
         (select left(t2.col2, charindex('_', t2.col2)) as output
         ) t3;
    

提交回复
热议问题