SQLTeam.com | Weblogs | Forums

Trimming a word from a sentence in sql


I have a data in a columnA of a table as given below, and I want to extract only wheel drive in separate solumn

and i want only wheel drive section from a sentence.like given below

Can anyone please suggest how to do this.


Use String Splitter with ";" delimiter and constrain to only values that are LIKE '% wheel drive'

SELECT	SplitterValue
FROM	YourTable AS T
	CROSS APPLY dbo.YourSplitterFunction(T.columnA, ';') AS X
WHERE	SplitterValue LIKE '% Wheel Drive'

declare @t as table
    val    varchar(100)

insert into @t
Select 'Four Wheel Drive'
Select 'Four Wheel Drive;Sedan'
Select 'Four Wheel Drive;HatchBack'
Select 'Four Wheel Drive;Transcode A727'
Select 'XLS Sport;Rear Wheel Drive'
Select 'Classic SLT; Rear Wheel Drive;Extended Cab Pickup;Front Torsion Bar'
Select 'SLT; Rear Wheel Drive;Standrard Cab Pickup'

select * , substring(val,CHARINDEX(' Wheel Drive', val)-4,16)
from @t


Thanks Viggneshwar.