SQL Server 2008 を使用して、これらの列の一部を $xxx,xxx.xx として返そうとしています。
これは私が使用しているクエリです(このクエリは、数値を計算##tempshow
して最後に選択するためだけに更新されます)
SELECT
CASE GROUPING(s.StoreID) WHEN 1 THEN '' ELSE s.StoreID END [StoreID],
CASE GROUPING(p.VendorID) WHEN 1 THEN '' ELSE p.VendorID END [VendorID],
SUM(d.Quantity) AS [UnitSold],
CAST(SUM(d.amount * d.quantity) AS DECIMAL(18,2)) AS Amount,
CAST(SUM(d.Discount) AS DECIMAL(18,2)) AS Discount,
CAST(SUM((d.Amount * d.Quantity - d.Discount)) AS DECIMAL(18,2)) AS ExtSold,
CAST(SUM(d.Cost * d.Quantity) AS DECIMAL(18,2)) AS Cost,
CAST(0 AS DECIMAL(18,2)) AS Profit,
CAST(0 AS DECIMAL(18,2)) AS OnHand,
CAST(0 AS DECIMAL(18,2)) AS OnHandRetail,
CAST(0 AS DECIMAL(18,2)) AS OnHandCost,
CAST(0 AS DECIMAL(18,2)) AS ReceivedCost,
CAST(0 AS DECIMAL(18,2)) AS ReceivedRetail,
CAST(0 AS DECIMAL(18,2)) AS ReceivedQty,
CAST(0 AS DECIMAL(18,2)) AS Margin,
CAST(0 AS DECIMAL(12,2)) AS TurnOver,
CAST(0 AS INTEGER) AS OnOrder
INTO
##tempshow
FROM
RPTrs s,
RPTrsd d,
RPIv i,
RPProducts p
WHERE
s.ReceiptNO = d.ReceiptNO and
s.StoreID = d.StoreID and
i.UPC = d.UPC and
i.StoreID = d.StoreID and
p.ProductID = i.IVProduct and
s.StoreID = '01' and
s.TRSDate > GETDATE()-20 and
p.Service = 0
GROUP BY
GROUPING SETS((s.StoreID,p.VendorID),())
どちらが返されます:
私が試してみました
CAST(SUM(d.amount * d.quantity) AS MONEY) AS Amount,
と
SUM(CAST((d.amount * d.quantity) AS MONEY)) AS Amount,
予想される出力 (およびこの列と同じ他の列Amount
):
|StoreID | VendorID | UnitSold | Amount
---------------------------------------------
1 | 01 | 0000 | 0 | $0.00
2 | 01 | am | 62 | $6,275.00
3 | 01 | AO | 58 | $18,964.00
4 | 01 | payless | 6 | $1,383.36
5 | | | 126 | $26,622.36
Amount, Discount, ExtSold, Cost, Profit, OnHandRetail, OnHandCost, ReceivedCost, ReceivedRetail
をマネー形式にする必要があります