Split string in sql server 2000

  • How to split string in sql server 2000

    suppose i have a string  Like this  ----

    <TD>

    <P align=justify><STRONG>Legal Perspective</STRONG> </P>

    <P align=justify><IMG height=206

    src="http://www.fsoutsourcing.com/images/bestCaptive.jpg" width=387></P>

    <P align=justify><B>By: </B><SPAN

    style="FONT-WEIGHT: 700; FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman">Paul

    J.N. Roy and Percival Billimoria Esq</SPAN></P>

    <P><STRONG>With its near-shore location and a strong domestic IT market, Brazil

    is actively promoting itself as an IT services offshore

    destination.</STRONG></P>

    <P>Many companies are increasingly interested in setting up offshore operations.

    While the cost savings and other rewards in doing so may be significant, there'   

    i want to remove <img....> tag from this string..

    Plz help...... i m in a great trouble...

    Plz..

  • Since your input is a xml document check out sp_xml_preparedocument.

    BOL has some examples.

    Markus

    [font="Verdana"]Markus Bohse[/font]

  • i don't understand. Plz give me example....

    Plz..

  • quoteSince your input is a xml document check out sp_xml_preparedocument

    The HTML given is not XML compliant

    One way to get the first img is

    STUFF(LEFT([value],CHARINDEX('>',[value],CHARINDEX('<img',[value]))),1,CHARINDEX('<img',[value])-1,'')

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Just thought

    Do you want to extract or remove the img tag

    Far away is close at hand in the images of elsewhere.
    Anon.

  • yes, i want to remove <img..> tage from whole string.....

    Plz explain in detail... I m New for SQL

  • Use PATINDEX or CHARINDEX to find the "". You can then use SUBSTRING to remove the middle piece.

    http://www.sqlservercentral.com/columnists/sjones/tamestrings1.asp

    http://www.sqlservercentral.com/columnists/sjones/20010424135929_1.asp

  •  

    substitute your field for @string.  This will remove the first instance assuming the html conforms to <IMG..yada..> with no '>' in the image tag.

     

    select substring(@string,1,charindex('<IMG',@string)-1) +

    substring(@string,charindex('>',@string,charindex('<IMG',@string))+1,len(@string)-charindex('>',@string,charindex('<IMG',@string))+1)


  • Thank you sir.

    thank you very much... My problem is solved now.

     

  • Hello use this.

    I have to made an SP to split a string character.

    I hope that be useful,

    Greetings.

    CREATE PROCEDURE SP_STRING_SPLIT (@String varchar(8000),@Separator Char(10),@pos_select int=0)

    AS

    BEGIN

    SET NOCOUNT ON

    DECLARE @Caracter varchar(8000)

    DECLARE @Pos int

    Set @Pos=1

    Set @Caracter=''

    CREATE TABLE #ARRAY

    ( String varchar(8000) NOT NULL,

    Pos int NOT NULL IDENTITY (1, 1)

    )

    While (@Pos<=len(@String))

    Begin

    If substring(@String,@Pos,1)=Ltrim(Rtrim(@Separator))

    Begin

    INSERT INTO #ARRAY SELECT @Caracter

    SET @Caracter=''

    End

    Else

    Begin

    --give shape the wordo

    Set @Caracter=@Caracter+substring(@String,@Pos,1)

    End

    If @Pos=len(@String)

    Begin

    INSERT INTO #ARRAY SELECT @Caracter

    End

    SET @Pos=@Pos+1

    End

    SELECT Pos,String FROM #ARRAY where (Pos=@pos_select Or @pos_select=0)

    END

    GO

    exec SP_STRING_SPLIT 'HELLO, HOW ARE YOU?',',',0

     

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply