Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Johnnybax1
Starting Member
5 Posts |
Posted - 2011-12-08 : 20:59:19
|
| Hi All,I have 4 tablesManufacturer Table sample dataManufacturer ID 12Manufacturer AsiaProduct Table sample dataProductID 100ProductName Bulb manufacturerid 12Supply TableSupplierID Suppliername ParentSupplierID 1 ROOT NULL 2 Hardware 1 3 Concrete 2 4 Appliances 2SupplyProductRel(many to many)SupplierID ProductID 2 1003 100I want something like a table with a joinProductID ProductName SupplierPhase1 SupplierPhase2 manufacturername 100 BULB HARDWARE|COncrete HARDWARE|Appliances ASIANOTE: SuppierPhase above is a concat between the root/sub level from supply table.A query or any other approach you guys suggest will be very helpful.Very urgent and important please!!!!Do suggest any other approaches. It is in vb.net |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-09 : 01:55:55
|
| [code];With CTEAS(SELECT p.ProductID ,p.ProductName,s1.Suppliername , ROW_NUMBER() OVER (PARTITION BY s1.SupplierID ORDER BY s2.SupplierID ) AS RnFROM SupplyProductRel spINNER JOIN Product pON p.ProductID =sp.ProductID INNER JOIN Supply s1ON ss.SupplierID = sp.SupplierIDINNER JOIN Supply s2ON s2.ParentSupplierID = s1.SupplierID)SELECT ProductID ,ProductName,Suppliername + '|'+ MAX(CASE WHEN Rn=1 THEN Suppliername ELSE NULL END) AS SupplierPhase1,Suppliername + '|'+ MAX(CASE WHEN Rn=2 THEN Suppliername ELSE NULL END) AS SupplierPhase2FROM CTEGROUP BY ProductID ,ProductName,Suppliername [/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|