Camillia
asked on
Get the data in a different format - maybe pivot?
This is SQL 2014
I have this sample data
I get 4 row. This is how I want it to look like. (I wanted to loop thru the #temp table, compare the "cid" and then maybe concat and dump the result into another table but that can't be the correct way of doing this)
I need the data in "Rank" column to be from earliest year (2014) to latest year (2015)
CId Year Rank Cname
1712 2014,2015 1,3 test1
1929 2014, 2015 2024,2302 test2
I have this sample data
create table #temp
(
rowId int identity,
cId int,
year int,
rank int,
cName varchar(500)
)
insert into #temp
select 1, 1712, 2015,3,'test1'
insert into #temp
select 2, 1929, 2015,2302,'test2'
insert into #temp
select 3, 1712, 2014,1,'test1'
insert into #temp
select 3, 1929, 2014,2024,'test2'
I get 4 row. This is how I want it to look like. (I wanted to loop thru the #temp table, compare the "cid" and then maybe concat and dump the result into another table but that can't be the correct way of doing this)
I need the data in "Rank" column to be from earliest year (2014) to latest year (2015)
CId Year Rank Cname
1712 2014,2015 1,3 test1
1929 2014, 2015 2024,2302 test2
ASKER
thanks. Let me try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank. I'll try today.
Open in new window