Welcome to Sign in | Help
in Search

sql server 2005 split pe coloana

Last post 11-26-2009, 4:10 PM by rsocol. 2 replies.
Sort Posts: Previous Next
  •  11-26-2009, 3:21 PM 7877

    sql server 2005 split pe coloana

    salut,

    am o coloana X intr-o tabela A de tip text

    inregistrarile in ea sunt de forma:

    ID                                          Continut

    1         text text ;CUI text text text.....text text ;CUI text text ..... text text ;CUI ....s.a.m.d.

    2         text text ;CUI text text text.....text text ;CUI text text ..... text text ;CUI ....s.a.m.d.

    .......

    cum pot scoate intr-o tabela tot ce este intre ;CUI pt un anume ID

    multumesc

    alex.

    p.s. am incercat cu functia asta dar nu o pot folosi pt campul de tip text, daca ar fi fost varchar(max) ar fi fost perfect

    alter FUNCTION [dbo].[Split]

    (

    @SearchString text,

    @Separator VARCHAR(200)

    )

    RETURNS @strtable TABLE (strval VARCHAR(8000))

    AS

    BEGIN

    DECLARE

    @tmpStr VARCHAR(8000),

    @intSeparatorLength INT

    SET @intSeparatorLength = LEN(@Separator)

    SET @tmpStr = @SearchString

    WHILE 1=1

    BEGIN

    INSERT INTO @strtable VALUES ( SUBSTRING(@tmpStr, 0 ,CHARINDEX(@Separator,@tmpStr)))

    SET @tmpStr = SUBSTRING(@tmpStr,CHARINDEX(@Separator,@tmpStr)+LEN(@Separator),8000)

    IF CHARINDEX(@Separator,@tmpStr) < 1

    BREAK

    END

    RETURN

    END

    go

     

     

  •  11-26-2009, 3:58 PM 7878 in reply to 7877

    Re: sql server 2005 split pe coloana

    am folosit variabila de tip varchar(max) si nu text sau (8000) si functioneaza....exista vreo solutie mai buna?

    alex.

  •  11-26-2009, 4:10 PM 7879 in reply to 7877

    Re: sql server 2005 split pe coloana

View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems