Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Pivot table

$
0
0

DECLARE  @SOURCE TABLE  
(FAMILY_ID INT,
CHILD_ID INT,
CHILD_FIRSTNAME VARCHAR(50))

INSERT INTO @SOURCE 
VALUES 
('060616754','1','A'),
('060616754','2','B'),
('060616754','3','C')

SELECT * FROM @SOURCE


DECLARE  @Destination TABLE  
(FAMILY_ID INT,
CHILD_ID1 INT,
CHILD_ID2 INT,
CHILD_ID3 INT,
CHILD1_FIRSTNAME VARCHAR(50),
CHILD2_FIRSTNAME VARCHAR(50),
CHILD3_FIRSTNAME VARCHAR(50))

INSERT INTO @Destination
VALUES 
('060616754','1','2','3','A','B','C')

The columns for the children can be dynamic or fixed ( max of 6 children) based on the Family_ID. For Example: A family can have 1 child or more than 1 child.

  

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>