我已经运行了一个查询以获得我满意的某些结果,但我现在想插入一段代码,这将迫使用户手动输入结果的日期范围。
到目前为止我的代码是......
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, CAST(SUM(COST) AS DECIMAL(12, 2)) AS TOTAL_COST
FROM (
SELECT COMPOUNDNAME AS CATEGORY_DESCRIPTION, COST
FROM vwREP_GP_ContractProjectPurchaseRpt
) A
GROUP BY
CATEGORY_DESCRIPTION
我正在考虑插入一串代码,例如......
SELECT * FROM vwREP_GP_ContractProjectPurchaseRpt
WHERE (DOC_DATE >= @DateFrom)
AND (DOC_DATE <= @DateTo)
但我被困在如何让它发挥作用上。
任何建议将不胜感激。
所有工作都在 SQL Server Management Studio 2005 上完成,最终将部署在 MS Visual Studio 上。
抱歉,我在粘贴代码时错过了这个。我这样声明我的变量...
DECLARE @DateFrom datetime
DECLARE @DateTo datetime
那么下面......
SELECT * FROM vwREP_GP_ContractProjectPurchaseRpt
WHERE (DOC_DATE >= @DateFrom)
AND (DOC_DATE <= @DateTo)
它所做的只是返回一个空白的结果窗格?