首页 > 解决方案 > 如何解析excel文件

问题描述

我在excel中有很多行,比如

TALLON | BLACK | 44

我需要提取管道之间的值

因此,我只需要获取BLACK上述示例行的值。如何提取这些值?

标签: sqlsql-server

解决方案


一种选择是使用带有(管道)的substring()函数作为搜索表达式charindex()|

with t(str) as
( 
 select 'TALLON | BLACK | 44' union all
 select 'LLON | BLUE| 47   ' union all
 select 'LON    |YELLOW| 56 '   
)
select substring(str, charindex('|',str,1)+1, 
               ( charindex('|',str, charindex('|',str,1)+1) - charindex('|',str,1) )-1 )
       as result             
  from t;

 result
--------
  BLACK
  BLUE
 YELLOW

Rextester 演示


推荐阅读