This is tricky and I'm stuck. I need to receive SKU details from a table that has inventory records, with added columns that have another SKU that's a match based on same size, same brand etc.
So the query I'm running is this:
SELECT h.orders_header_id,
h.order_number,
CONVERT(VARCHAR,h.order_date, 102) AS order_date,
h.first_sku,
h.first_title,
i.size,
i.brand,
i.pic,
i.channel,
h.c_email,
h.delivery_status
FROM orders_header h
LEFT JOIN
(SELECT sku,
SIZE,
brand,
imageserver + sku + 'A.JPG' AS pic,
channel
FROM inv_ALL) i ON h.first_sku = i.sku
WHERE h.delivery_status LIKE '%|Delivered|%'
AND h.delivery_status NOT LIKE '%Arrival in Destination Country%'
AND h.delivery_status LIKE (CONVERT(VARCHAR, GETDATE(), 112) +'%')
AND i.pic IS NOT NULL
What I need is to have these columns:
S1,S1title,S1pic,S2,S2title,S2pic,S3,S3title,S3pic
Where S1 would be a matching SKU pulled from inv_ALL table that has same size and brand as h.first_sku and non-zero i.availablequantity. S1title would be it's title and S1pic would be it's picture (as above). Same for S2 and S3. And S1/S2/S3 have to be SKUs other than first_sku.
These are supposed to be 'Top Picks' to be shown to customers along with their purchase as a recommendation.
I have been trying since yesterday, but can't think of a way to make it pull these records in the same row as added columns.
(Microsoft SQL Server 2014 - 12.0.2000.8 (X64) Feb 20 2014 20:04:26 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1)
Here's a screenshot of what the results look like right now: