Reputation: 1918
I have a following string
90-PMR-450
90-PMRA-340
I want to get part 3 of string. example 450
or 340
.
plese help me. thanks
Upvotes: 2
Views: 1126
Reputation: 280644
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;
Upvotes: 2
Reputation: 139010
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
Upvotes: 3
Reputation: 8333
i think you will find this user defined function to split the string helpful:
http://www.codeproject.com/Articles/7938/SQL-User-Defined-Function-to-Parse-a-Delimited-Str
Upvotes: 1