当前位置: 代码迷 >> Sql Server >> 查找字符串的语句,该怎么解决
  详细解决方案

查找字符串的语句,该怎么解决

热度:115   发布时间:2016-04-27 19:20:37.0
查找字符串的语句
字符串:
字段(A)
1A00-DA001-0550
1B001-DA002-0558

请问如何可以查出第二个 "-"后四位字符串

------解决方案--------------------
select substring(substring(a,charindex('-',a,1)),1,charindex('-',substring(a,charindex('-',a,1)))) -1 ) from table
------解决方案--------------------
SQL code
select reverse(left(reverse(a),charindex('-',reverse(a))-1)) from tb
------解决方案--------------------
SQL code
create table tb(a varchar(20))insert into tb values('1A00-DA001-0550') insert into tb values('1B001-DA002-0558')select reverse(left(reverse(a),charindex('-',reverse(a))-1)) from tbdrop table tb/*-------------------- 05500558(所影响的行数为 2 行)*/
------解决方案--------------------
SQL code
SELECT REVERSE(STUFF(REVERSE(A),CHARINDEX('-',REVERSE(A)),LEN(A),''))
  相关解决方案