0

I was working on stored procedure to return rows with columns from multiple table

First Table- Product Variant

Columns are - Sku, Name, Price, MRP, Cost

Second Table - Sku_Mrp_Mapping

Columns are - Sku, MRP, Cost

Third Table- Sku_Barcode_Mapping

Columns are - Sku, Barcode

My query

SELECT     pv.Sku, pv.ProductCost, pv.Price, pv.Mrp,sb.Barcode,
           sm.MRP, sm.Cost
FROM         ProductVariant AS pv INNER JOIN
                      LEFT OUTER JOIN
                      Sku_MRP_Mapping AS sm ON sm.Sku = pv.Sku LEFT OUTER JOIN
                      Sku_Barcode_Mapping AS sb ON sb.SKU = pv.Sku
WHERE     (p.Deleted = 0) AND (pv.Deleted = 0) and pv.Sku='100003'

ORDER BY pv.Sku

This result in 42 rows as for sku 100003 there are 7 barcodes and 6 different Mrp and cost. My rows look like

For my Sku 100003 rows in Sku_Mrp_Mapping table are

Id    Sku    MRP     Cost
1   100003  65.00   58.19
2   100003  68.00   60.87
3   100003  72.00   64.45
4   100003  75.00   67.14
5   100003  78.00   69.83
6   100003  80.00   71.63

For my Sku 100003 rows in Sku_Barcode_Mapping table are

Id      SKU        Barcode
87942   100003  8901314009159
87943   100003  10000310
87944   100003  89013140090
87945   100003  8901314009081
87946   100003  8901314009111
87947   100003  8901314009159
87948   100003  10000320

Now I want to return single rows for sku 100003 with all barcodes in single column separated by comma and same for MRP and cost.

Note that I have taken 100003 sku as an example, there are many rows in productvariant which i want to return.

Nitin Varpe
  • 10,450
  • 6
  • 36
  • 60
  • @marc_s couldnt get the expected answer from ur link, can u specify more precise solution? – Nitin Varpe Jan 21 '14 at 08:19
  • Try [How to make a query with group_concat in sql server](http://stackoverflow.com/questions/17591490/how-to-make-a-query-with-group-concat-in-sql-server) which has the usual for xml path solution. Or just search for sql server group_concat. – OGHaza Jan 21 '14 at 10:02

0 Answers0