我有以下查询....
SELECT NGPCostPosition.ProjectNo, NGPCostPosition.CostCat,
NGPCostPosition.DocumentNumber, NGPCostPosition.TransactionDate,
NGPCostPosition.UnitCost, NGPCostPosition.TotalCost,
NGPCostPosition.CreditorEmployeeName, NGPCostPosition.SummaryCostCat,
PurchaseNGP_PL.CalculatedCost,
CASE
WHEN
DATEPART(MONTH, NGPCostPosition.TransactionDate) = DATEPART(MONTH, GETDATE())
AND
DATEPART(YEAR, NGPCostPosition.TransactionDate) = DATEPART(YEAR, GETDATE())
THEN TotalCost
ELSE 0
END AS CurrentMonthCost2
FROM NGPCostPosition INNER JOIN
PurchaseNGP_PL
ON NGPCostPosition.ProjectNo = PurchaseNGP_PL.PAPROJNUMBER
AND NGPCostPosition.DocumentNumber = PurchaseNGP_PL.DocumentNumber
AND NGPCostPosition.SummaryCostCat = PurchaseNGP_PL.SummaryCostCat
WHERE NGPCostPosition.ProjectNo = @ProjectNumber
AND CostCat ='P070'
OR CostCat ='P080'
AND NGPCostPosition.ProjectNo = @ProjectNumber
AND NGPCostPosition.TotalCost = ABS(PurchaseNGP_PL.CalculatedCost)
GROUP BY NGPCostPosition.ProjectNo,
NGPCostPosition.CostCat,
NGPCostPosition.DocumentNumber,
NGPCostPosition.TransactionDate,
NGPCostPosition.UnitCost,
NGPCostPosition.TotalCost,
NGPCostPosition.CreditorEmployeeName,
NGPCostPosition.SummaryCostCat,
PurchaseNGP_PL.CalculatedCost
这给了我以下结果......
我想要做的是将“ProjectNo”列限制为仅前 5 个数字。(例如 12169)
有人可以建议这是否可行,最好的方法是什么?