Split Numbers

  • I am trying to get the latest PO number if it is in the table. And then prefix it with Region Code.

    I was able to do so for One PO number. Can someone advise how do I so do for rows with Multiple PO's

    The Output I expect is NA1450

    NA3420

    NA2001

    CREATE TABLE #tbl_data (

    Region Varchar(25),

    PONumber Varchar(50),

    );

    INSERT INTO #tbl_data (

    Region,

    PONumber

    )

    VALUES

    ( 'North America','1450'),

    ( 'North America' ,'old PO 1440 New PO 3420'),

    ( 'North America' ,'1389 - old 2001 - New')

    --( NULL, 'BC');

    --Drop table #tbl_data

    Select * from #tbl_data

    Thanks

  • A pattern splitter can help you with this and I hope that you can complete the solution.

    Reference: http://www.sqlservercentral.com/articles/String+Manipulation/94365/

    Select *

    from #tbl_data

    CROSS APPLY (SELECT TOP 1 Item

    FROM dbo.PatternSplitCM( PONumber, '%[0-9]%') s

    WHERE Matched = 1

    ORDER BY ItemNumber DESC) PO

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 2 posts - 1 through 1 (of 1 total)

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