I´ve to create a SELECT over many tables. The output has to be specified as it is (output via SQLCMD in a file)
The problem is, that there are too many lines in the output.
the code (from MS SQL Server Management Express):
SELECT DISTINCT
AORDER.cOrderId AS 'order-id', APOS.cOrderItemId AS 'order-item-id', 'CustomerReturn' AS 'adjustment-reason-code', AORDER.cCurrency AS currency,
CONVERT(DECIMAL(16, 2), ROUND(GSPOS.fVKPreis * GSPOS.nAnzahl, 2)) AS 'item-price-adj', CONVERT(DECIMAL(16, 2),
CASE WHEN GSPOS.nAnzahl = APOS.nQuantityPurchased THEN ROUND(APOS.fShippingPrice, 2) ELSE '0.00' END) AS 'shipping-price-adj',
GSPOS.nAnzahl AS quantity
FROM tgutschriftpos AS GSPOS INNER JOIN
tgutschrift AS GS ON GSPOS.tGutschrift_kGutschrift = GS.kGutschrift INNER JOIN
tbestellung AS B ON GS.kRechnung = B.tRechnung_kRechnung INNER JOIN
pf_amazon_bestellung AS AORDER ON B.cInetBestellNr = AORDER.cOrderId INNER JOIN
pf_amazon_bestellungpos AS APOS ON AORDER.kAmazonBestellung = APOS.kAmazonBestellung AND GSPOS.cArtNr = APOS.cArtNr
WHERE (APOS.cOrderItemId IS NOT NULL) AND (GS.cStatus IS NULL) AND (NOT (GSPOS.tArtikel_kArtikel = 0)) AND (NOT (GSPOS.cArtNr IS NULL))
GROUP BY GSPOS.kGutschriftPos, AORDER.cOrderId, GSPOS.nAnzahl, GSPOS.fVKPreis, APOS.cOrderItemId, AORDER.cCurrency, APOS.nQuantityPurchased,
APOS.fShippingPrice
The output as it is:
123456789 12345 CustomerReturn EUR 14,95 0,00 1,0000
123456789 12345 CustomerReturn EUR 29,90 3,87 2,0000
123456789 6789 CustomerReturn EUR 14,95 1,93 1,0000
123456789 6789 CustomerReturn EUR 29,90 0,00 2,0000
The output as it should be:
123456789 12345 CustomerReturn EUR 14,95 0,00 1,0000
123456789 6789 CustomerReturn EUR 14,95 1,93 1,0000
I hope someone can help me?
Thanks,
Rene