2012-02-29 77 views
2

分割字符串值我有以下字符串
如何在SQLSERVER

90-PMR-450 
90-PMRA-340 

我想要得到的字符串的第3部分。示例450340

plese幫助我。感謝

回答

3
declare @T table 
(
    Value varchar(15) 
) 

insert into @T values 
('90-PMR-450'), 
('90-PMRA-340') 

select stuff(Value, 1, 1+len(Value)-charindex('-', reverse(Value)), '') 
from @t 
2
DECLARE @x TABLE(v VARCHAR(32)); 

INSERT @x SELECT '90-PMR-450' 
UNION ALL SELECT '90-PMRA-340'; 

SELECT Part3 = PARSENAME(REPLACE(v, '-', '.'), 1) FROM @x;