Hi,
I have a table like below
CREATE TABLE #Table (Code varchar(50),Qty Float,SupName VARCHAR(10),SupQty float,SupPrice decimal(18,3))
insert into #Table VALUES ('Code1',10,'Supplier1',10,20)
insert into #Table VALUES ('Code1',10,'Supplier2',6,25)
insert into #Table VALUES ('Code2',10,'Supplier1',10,15)
insert into #Table VALUES ('Code3',10,'Supplier1',10,30)
insert into #Table VALUES ('Code3',10,'Supplier2',10,28)
select * from #Table
drop Table #Table
I need the result as below script
CREATE TABLE #Result (Code varchar(50),Qty Float,Supplier1Qty float,Supplier1Price decimal(18,3),Supplier2Qty float,Supplier2Price decimal(18,3),LowestSup varchar(10),
LowestSupQty float,LowestSupPrice decimal(18,3))
insert into #Result VALUES ('Code1',10,10,20,6,25,'Supplier1',10,20)
insert into #Result VALUES ('Code2',10,10,15,NULL,NULL,'Supplier1',10,15)
insert into #Result VALUES ('Code3',10,10,30,10,28,'Supplier2',10,28)
select * from #Result
drop Table #Result
Supplier name should be as column. supplier name is not static column, it will dynamically increase/decrease. the last three column states that the lowest in the values.
Regards
Kasim