February 18, 2014 at 5:24 pm
I have an xml stored in a coulum of a table and I use the following query to extract an xml element :
select CONVERT(XML,CONVERT(NVARCHAR(max),Response)).value('(/Quote/error)[1]','nvarchar(max)') as Excepiton .
The result of the expression is :
TL43:The product has no marked price.;
I would like to select only the code : TL43
and then seperately I would like to select The product has no marked price.
Is there a way I can do it ?`
February 18, 2014 at 5:30 pm
You could use CHARINDEX and SUBSTRING functions like this:
WITH Samp AS(
SELECT 'TL43:The product has no marked price.;' AS SomeText
)
SELECT LEFT( SomeText, CHARINDEX(':', SomeText) - 1),
SUBSTRING(SomeText, CHARINDEX(':', SomeText) + 1, CHARINDEX(';', SomeText)-CHARINDEX(':', SomeText)-1 /*Or change this to a large number to include all the rest of the string*/)
FROM Samp
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply