May 12, 2015 at 10:00 am
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
May 12, 2015 at 11:13 am
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
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply