Skip to Content
author's profile photo Former Member
Former Member

Create Splitter Function in SAP HANA

Hi All,

I am trying to create a same below function created in MS-SQL in HANA. I not able to achieve this creation.

Can anyone please help me with converting the same into HANA.

MS-SQL Function

--------------------------

Create Function fnSplitter (@IDs Varchar(4000) )

Returns @Tbl_IDs Table (ID nvarchar(100) COLLATE SQL_Latin1_General_CP1_CS_AS ) As

Begin

Set @IDs = @IDs + ','

Declare @Pos1 Int

Declare @Pos2 Int

Set @Pos1=1

Set @Pos2=1

While @Pos1<Len(@IDs)

Begin

Set @Pos1 = CharIndex(',',@IDs,@Pos1)

Insert @Tbl_IDs Select Substring(@IDs,@Pos2,@Pos1-@Pos2)

Set @Pos2=@Pos1+1

Set @Pos1 = @Pos1+1

End

Return

End

Thanks

Muralidhar

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on Feb 19, 2015 at 07:08 PM

    What should this function do?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2015 at 09:00 PM

    Should be pretty straight forward...theres more then few versions of splitter function...for intance from my 2008 version (if thats what You need)

    ..should be asy to reweite in Hana...cant access Hana from home, so I won't do it for You, sorry.

    --example fo use --select * from dbo.fnSplit('Idem,doma,dosta,je', ',')

    ALTER FUNCTION dbo.fnSplit(
    @sInputList VARCHAR(8000) -- Lista
    , @sDelimiter VARCHAR(8000) = ',' -- odvaja
    ) RETURNS @List TABLE (item VARCHAR(8000))

    BEGIN
    DECLARE @sItem VARCHAR(8000)
    WHILE CHARINDEX(@sDelimiter,@sInputList,0) <> 0
    BEGIN
    SELECT
    @sItem=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX
    (@sDelimiter,@sInputList,0)-1))), @sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX
    (@sDelimiter,@sInputList,0)+LEN(@sDelimiter),LEN(@sInputList))))

    IF LEN(@sItem) > 0
    INSERT INTO @List SELECT @sItem
    END

    IF LEN(@sInputList) > 0
    INSERT INTO @List SELECT @sInputList
    RETURN
    END
    GO


    Hope this helps

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2015 at 09:06 PM

    This is it, allready discussed

    etc

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 06, 2015 at 04:39 PM

    This message was moderated.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.