Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to get value portion key to every 3 row on one row meaning

rn 1,2,3 one row KRM__21X0E100C0ADD
rn 1,2,3 one row KRM__21X0J100K0ADD
rn 1,2,3 on one row KRM__21X1C100D0ADD

SELECT P.GlobalPnId,P.PortionKey,f.*, f.value + P.PortionKey AS ValuePortionKey
FROM #portiontable p 
INNER JOIN #finaltable f ON p.rn = f.rn


GlobalPnId	PortionKey	value	RN	ValuePortionKey
37599	100	KRM__21X0E	1	KRM__21X0E100
37599	0AD	C	2	C0AD
37599	D		3	D
37599	100	KRM__21X0J	1	KRM__21X0J100
37599	0AD	K	2	K0AD
37599	D		3	D
37599	100	KRM__21X1C	1	KRM__21X1C100
37599	0AD	D	2	D0AD
37599	D		3	D


I need to get from 1 to 3 on one rows as following :

final result I need to get as below :
KRM__21X0E100C0ADD
KRM__21X0J100K0ADD
KRM__21X1C100D0ADD



exactly i need one row above display on 3 parts as

Final Result :

SQL
ValuePortionKey
KRM__21X0E100C0ADD
KRM__21X0J100K0ADD
KRM__21X1C100D0ADD


What I have tried:

SELECT SUBSTRING((SELECT ''+ft.value + PortionKey
         FROM (
         SELECT P.GlobalPnId,P.PortionKey,f.*, f.value + P.PortionKey AS ValuePortionKey
FROM #portiontable p 
INNER JOIN #finaltable f ON p.rn = f.rn
         ) ft
FOR XML PATH('')),1,1000) as PartSignature

but i get wrong result because result display all on one row :slight_smile:
PartSignature
KRM__21X0E100C0ADDKRM__21X0J100K0ADDKRM__21X1C100D0ADD
Posted
Updated 7-Mar-21 8:33am
v2
Comments
RedDk 7-Mar-21 15:31pm    
I've been trying to work through this problem and have come to the disconnect which is the table definition "#finaltable". I could continue to work through it using my substitute for the origin table (the data which you provide is contained now in it) but without any structure ... I'm going to call it quits.

So, some CREATE TABLE code would be useful ...

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