Click here to Skip to main content
15,923,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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
Posted
Comments
CHill60 20-Feb-23 6:05am    
I'm pretty sure you've been told before that using comma separated data is a Bad Design decision. However, you've provided expected results but no sample data, which makes it very difficult for us to help you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900