日期:2014-05-18  浏览次数:20545 次

查找字符串的语句
字符串:
字段(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 tb

drop table tb

/*
-------------------- 
0550
0558

(所影响的行数为 2 行)
*/

------解决方案--------------------
SQL code
SELECT REVERSE(STUFF(REVERSE(A),CHARINDEX('-',REVERSE(A)),LEN(A),''))