I working on SQL server 2012 I face issue i can't display Print Server with vBranchDesc
by using only one select statement instead of two select statement .
i convert values separated comma to rows Id on first select statement .
then on second select statement I get branch name text by join id .
so How to make two select statement on one select
expected result
PrintServer vBranchDesc
1 Non-Trade Store
1 Al Tay Warehouse
2 Jumeirah
3 Aweer
2 Barsha South
2 Al Barsha Hessa ST Branch
What I have tried:
SELECT PrintServer ,
Split.A.value('.', 'VARCHAR(4000)') AS BranchId
into #t1
FROM (SELECT BranchCode, PrintServer,
CAST ('<M>' + REPLACE(BranchCode, ',', '</M><M>') + '</M>' AS XML) AS String
FROM [dbo].[tbl_branchPDFexe]) AS A CROSS APPLY String.nodes ('/M') AS Split(A);
select t.PrintServer,b.vBranchDesc from #t1 t inner join [dbo].[tbl_Branch] b with(nolock) on t.BranchId=b.iBranchCode