I have one table:
Product Master:
Product_ID ProductName
0001 A
0001 A1
0002 B
0002 B1
0003 C
I want Retrive Product_Name as Columns Like:
0001 A A1
0002 B B1
0003 C
Pankaj Kumar ChoudharyPosted Jun 2, 2015, 2:20 AM
(
select * from
(
select *,ROW_NUMBER() over(Partition by Product_id Order By Product_Id) as Row_ from Product_master
)Tab
)Tab
where Tab.Row_=1
)Tab
select * Into ##tmp1 from (select Tab.Product_id ,Tab.Product_name From
(
select * from
(
select *,ROW_NUMBER() over(Partition by Product_id Order By Product_Id) as Row_ from Product_master
)Tab
)Tab
where Tab.Row_=2
)Tab
Select ##tmp.Product_ID , ##tmp.Product_Name + ' '+ (case when ##tmp1.Product_Name is not null then ##tmp1.Product_Name else ' ' end) as Name from ##tmp
left outer join
##tmp1
on
##tmp.Product_ID=##tmp1.Product_ID
Drop table ##tmp , ##tmp1