我設計了以下視圖並試圖將其用作存儲過程;但是,我的存儲過程不會返回與我的視圖相同的行。我的存儲過程不會返回行,但是我的視圖確實是
我的觀點返回46行:
SELECT
NDC_Text, Trade_Name, Vendor_Code, SUM(Quantity_Received) AS QTY,
SUM(CASE WHEN Cost_Center = 7070 THEN Cost_Center_Dollars ELSE 0 END) AS [7070],
SUM(CASE WHEN Cost_Center = 7071 THEN Cost_Center_Dollars ELSE 0 END) AS [7071],
SUM(CASE WHEN Cost_Center = 7700 THEN Cost_Center_Dollars ELSE 0 END) AS [7700],
SUM(CASE WHEN Cost_Center = 7701 THEN Cost_Center_Dollars ELSE 0 END) AS [7701],
SUM(CASE WHEN Cost_Center = 7702 THEN Cost_Center_Dollars ELSE 0 END) AS [7702],
SUM(CASE WHEN Cost_Center = 7703 THEN Cost_Center_Dollars ELSE 0 END) AS [7703],
SUM(CASE WHEN Cost_Center = 7703 THEN Cost_Center_Dollars ELSE 0 END) AS [7705],
SUM(Cost_Center_Dollars) AS Total, Program_Type
FROM dbo.VDP_Master_Drug_Receipts_Log
WHERE Date_Entered BETWEEN '10/1/2011' AND '11/1/2011'
AND (Program_Type = 'VDP-BULK')
GROUP BY NDC_Text, Trade_Name, Vendor_Code, Program_Type
ORDER BY Trade_Name
我的存儲過程
GO ALTER PROCEDURE [dbo].[ShowProductByCategory](@StartDate DateTime, @EndDate DateTime, @Type Varchar(15))
AS
Return
SELECT NDC_Text, Trade_Name, Vendor_Code, SUM(Quantity_Received) AS QTY,
SUM(CASE WHEN Cost_Center = 7070 THEN Cost_Center_Dollars ELSE 0 END) AS [7070],
SUM(CASE WHEN Cost_Center = 7071 THEN Cost_Center_Dollars ELSE 0 END) AS [7071],
SUM(CASE WHEN Cost_Center = 7700 THEN Cost_Center_Dollars ELSE 0 END) AS [7700],
SUM(CASE WHEN Cost_Center = 7701 THEN Cost_Center_Dollars ELSE 0 END) AS [7701],
SUM(CASE WHEN Cost_Center = 7702 THEN Cost_Center_Dollars ELSE 0 END) AS [7702],
SUM(CASE WHEN Cost_Center = 7703 THEN Cost_Center_Dollars ELSE 0 END) AS [7703],
SUM(CASE WHEN Cost_Center = 7703 THEN Cost_Center_Dollars ELSE 0 END) AS [7705],
SUM(Cost_Center_Dollars) AS Total, Program_Type
FROM dbo.VDP_Master_Drug_Receipts_Log
WHERE Date_Entered BETWEEN @StartDate AND @StartDate
AND (Program_Type = 'Type')
GROUP BY NDC_Text, Trade_Name, Vendor_Code, Program_Type
ORDER BY Trade_Name
感謝您的幫助。我已將存儲過程中的代碼更改爲「WHERE Date_Entered BETWEEN」@StartDate「AND」@EndDate「AND(Program_Type =」@Type「) GROUP BY NDC_Text,Trade_Name,Vendor_Code,Program_Type ORDER BY Trade_Name」仍然返回值爲0作爲SQL SSMS中的INT字段。它可以是商店程序中的「返回」。 –
@JavonFisher這個評論可能是更新你的問題的好東西,所以它會得到更多的曝光(並且查詢更改會更容易閱讀) –
@JavonFisher當然,我沒有注意到RETURN。由於marc_s說你需要刪除它。 –