This is the sample output
Let me explain what’s going on:
The query returns all invoices # of every year along with the products
that is involved in the invoice.
As you see, we have two invoice in 2010…The invoices are 30463 and 30516.
The invoice 30463 has 4 products, its shipping price is 105.88. As you see
the shipping price is repeated on every product which causes troubles when
i calculate sum at reporting level. The 4 products of invoice # 30463 has
shipping price of 105.00 overall. I want every shipping price of every invoice
to be shown only once regardless how many products within an invoice. How can i achieve it?
HERE IS THE QUERY:
SELECT
DATEPART(year, CustomerInvDetail.sentDate) AS "Year",
CustomerInvoice.cuInvoiceID,
Product.productName,
CustomerQuoteProducts.unitPrice,
CustomerQuoteProducts.qty,
CustomerQuoteProducts.qty * CustomerQuoteProducts.unitPrice AS "Price",
CustomerShipping.shippingPrice
FROM CustomerInvoice INNER JOIN CustomerInvDetail
ON CustomerInvoice.cuInvoiceID = CustomerInvDetail.cuInvoiceID
INNER JOIN CustomerQuote
ON CustomerQuote.customerQuoteID = CustomerInvoice.customerQuoteID
INNER JOIN CustomerQuoteProducts
ON CustomerQuoteProducts.customerQuoteID = CustomerQuote.customerQuoteID
INNER JOIN CustomerShipping
ON CustomerShipping.customerQuoteID = CustomerInvoice.customerQuoteID
INNER JOIN Customer
ON Customer.customerID = CustomerQuote.customerID
INNER JOIN Product
ON CustomerQuoteProducts.productID = Product.productID
WHERE (DATEPART(year, CustomerInvDetail.sentDate) BETWEEN 2001 AND 2022) AND (Customer.customerID = 500)
Something along these lines maybe?
Update
What it does is this:
cuInvoiceIdvaluenewid()which basically means enumerate those rows randomly.case ... = 1I want the very first row to be the one that would displayshippingPriceand all others —null.