July 30, 2015 at 10:44 am
I have a table where there are two managers in the Name section together . When I try to filter it with = it results in an error.
I want to split it in two rows and pass the respective name to retrieve data.Tried XML and usde the split function but looks like its not splitting...Any Idea...
Here it is .
CREATE TABLE #tbl_data (
Manager Varchar(25),
Device Varchar(20))
INSERT INTO #tbl_data (
Manager,
Device
)
VALUES
( 'Andy','ABC123'),
( 'John ,Sue' ,'XYZ456')
--( NULL, 'BC');
--Drop table #tbl_data
Select * from #tbl_data
XML ...
Select Device , Manager from (Select Device , CAST ('<M>' + REPLACE(Manager, ';', '</M><M>') + '</M>' AS XML) AS Manager FROM #tbl_data) A
CROSS APPLY Manager.nodes('/M') AS Split(a)
July 30, 2015 at 11:06 am
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply