0
私は同じフィールドで4つの異なる計算を返すスクリプトを作成しようとしていますが、実際に結果を単一の行に戻したいと思っています。mssql select文結果の単一行
現在、結果があるときに結果ごとに新しい行が返されます。
SELECT DISTINCT
sp.PartNumber,
(StandardUnitMaterialCost+StandardUnitRunCost+StandardUnitSetCost+StandardUnitSubcontractCost+StandardLandedCost1+StandardLandedCost2+StandardLandedCost3+StandardLandedCost4+StandardLandedCost5)
,
(select ISNULL(sum(quantity),0) from stores.StockLogPart where month(TransactionDate) < MONTH(getdate()) AND year(TransactionDate) <= year(getdate()) AND slp.PartID = Stores.StockLogPart.PartID)
,
(select ISNULL(sum(quantity),0) from stores.StockLogPart where month(TransactionDate) = MONTH(getdate()) AND year(TransactionDate) <= year(getdate()) AND slp.PartID = Stores.StockLogPart.PartID)
,
(select ISNULL(sum(quantity),0) from stores.StockLogPart where month(TransactionDate) = MONTH(getdate()) AND year(TransactionDate) <= year(getdate()) AND slp.TransactionCodeID IN (1,2,13) AND slp.PartID = Stores.StockLogPart.PartID)
,
(select ISNULL(sum(quantity),0) from stores.StockLogPart where month(TransactionDate) = MONTH(getdate()) AND year(TransactionDate) <= year(getdate()) AND slp.TransactionCodeID IN (3,7) AND slp.PartID = Stores.StockLogPart.PartID)
FROM Stores.StockLogPart slp
JOIN Structure.Parts sp ON sp.PartID = slp.PartID
JOIN Stores.ProductGroups pg ON pg.ProductGroupID = sp.ProductGroupID
WHERE pg.ProductGroupCode = 'XX'
しかし、複数の行があると思われます.pg.ProductGroupCode = 'XX'。あなたは同じ行に複数のTransactionDateを取得するつもりはありません。 – Paparazzi