Function to Read a String / JSON XML

 
select TDW.dbo.fn_ReadXML('<BasicColour xmlns="https://localhost/Schema/CdiCommonTypes">WHITE</BasicColour>', '<BasicColour xmlns="https://localhost/Schema/CdiCommonTypes">', '</BasicColour>')
 
create or alter function dbo.fn_ReadXML (@FieldBase varchar(max), @StrStart varchar(max), @StrEnd varchar(Max))
Returns varchar(1000)
AS 
Begin
Declare @StrStartSize int,
@StrStartPI int,
@StrStartPF int,
@StrStartDiff int,
@StrFinal varchar(max)
 
Set @StrStartSize = len(@StrStart)
Set @StrStartPI = charindex(@StrStart,@FieldBase)
Set @StrStartPF = charindex(@StrEnd,@FieldBase)
Set @StrStartDiff =  @StrStartPF - (@StrStartPI + @StrStartSize)
 
Set @StrFinal = iif(@StrStartDiff>0, substring(@FieldBase, (@StrStartPI + @StrStartSize) ,@StrStartDiff),'')
 
 
Return(@StrFinal)