我已經運行查詢以獲得某些結果,但我現在想插入一段代碼,這將強制用戶手動爲結果輸入日期範圍。SQL日期插入
我的代碼到目前爲止.....
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上。
SORRY粘貼我的代碼時錯過了這個。我宣佈我的可變因素是這樣的...
DECLARE @DateFrom datetime
DECLARE @DateTo datetime
那麼下面.....
SELECT * FROM vwREP_GP_ContractProjectPurchaseRpt
WHERE (DOC_DATE >= @DateFrom)
AND (DOC_DATE <= @DateTo)
所做的只是返回空白結果窗格?
那麼你有什麼嘗試,爲什麼卡住了?它的哪一方面會導致你的問題? –
如果您發佈代碼,XML或數據樣本,請**在文本編輯器中突出顯示這些行,然後單擊編輯器工具欄上的「代碼示例」按鈕(「{}」)以精確地格式化和語法突出顯示它! –
你應該考慮在你的查詢中使用表別名,這將使他們更容易閱讀。 – Taryn