我在 SQL Server Management Studio 2005 中运行了一个 SQL 查询,当我的结果来自我的Total_Cost
列时,我的列没有按照我想要的格式进行格式化。
我曾尝试添加一个Declare @TOTAL_COST decimal(12,2)
子句,但似乎无法使其正常工作,因此再次将其取出。
我的查询是:-
SELECT
vwREP_GP_ContractProjectPurchaseCostCatID.PACOSTCATID AS COST_CAT_CODE,
vwREP_GP_ContractProjectPurchaseCostCatID.PACOSTCATNME AS COST_CAT_NAME,
vwREP_GP_ContractProjectPurchaseRpt.COST,
vwREP_GP_ContractProjectPurchaseRpt.ITEMDESC AS ITEM,
vwREP_GP_ContractProjectPurchaseRpt.CREDITOR,
vwREP_GP_ContractProjectPurchaseRpt.DOC_NUM AS DOCUMENT_NUMBER,
vwREP_GP_ContractProjectPurchaseRpt.DESCRIPTION,
vwREP_GP_ContractProjectPurchaseRpt.DOC_DATE AS DATE,
vwREP_GP_ContractProjectPurchaseRpt.PROJECT AS JOB_CODE_STAGE,
vwREP_GP_ContractProjectPurchaseRpt.COMPOUNDNAME AS CATEGORY_DESCRIPTION
FROM
vwREP_GP_ContractProjectPurchaseCostCatID
INNER JOIN
vwREP_GP_ContractProjectPurchaseRpt ON vwREP_GP_ContractProjectPurchaseCostCatID.PACOSTCATID = vwREP_GP_ContractProjectPurchaseRpt.PACOSTCATID
SELECT
CATEGORY_DESCRIPTION, SUM(COST) AS TOTAL_COST
FROM
(SELECT
COMPOUNDNAME AS CATEGORY_DESCRIPTION, COST
FROM
vwREP_GP_ContractProjectPurchaseRpt
) A
GROUP BY
CATEGORY_DESCRIPTION
这给了我我正在寻找的结果,但Total_Cost
产生的数字是 5 位十进制格式。
例如:
156713.55000
获得结果以阅读以下内容的最佳方法是什么 -
156713.55
提前致谢