我創建了一個包含NBA球員統計數據的數據庫,僅用於練習SQL和SSRS。我是使用存儲過程的新手,但是我創建了下面的過程,應該(我認爲)允許我指定團隊和分鐘數。無法在SQL查詢中檢索新數據
CREATE PROCEDURE extrapstats
--Declare variables for the team and the amount of minutes to use in --calculations
@team NCHAR OUTPUT,
@minutes DECIMAL OUTPUT
AS
BEGIN
SELECT p.Fname + ' ' + p.Lname AS Player_Name,
p.Position,
--Creates averages based on the number of minutes per game specified in @minutes
(SUM(plg.PTS)/SUM(plg.MP))*@minutes AS PTS,
(SUM(plg.TRB)/SUM(plg.MP))*@minutes AS TRB,
(SUM(plg.AST)/SUM(plg.MP))*@minutes AS AST,
(SUM(plg.BLK)/SUM(plg.MP))*@minutes AS BLK,
(SUM(plg.STL)/SUM(plg.MP))*@minutes AS STL,
(SUM(plg.TOV)/SUM(plg.MP))*@minutes AS TOV,
(SUM(plg.FT)/SUM(plg.MP))*@minutes AS FTs,
SUM(plg.FT)/SUM(plg.FTA) AS FT_Percentage,
(SUM(plg.FG)/SUM(plg.MP))*@minutes AS FGs,
SUM(FG)/SUM(FGA) as Field_Percentage,
(SUM(plg.[3P])/SUM(plg.MP))*@minutes AS Threes,
SUM([3P])/SUM([3PA]) AS Three_Point_Percentage
FROM PlayerGameLog plg
--Joins the Players and PlayerGameLog tables
INNER JOIN Players p
ON p.PlayerID = plg.PlayerID
AND TeamID = @team
GROUP BY p.Fname, p.Lname, p.Position, p.TeamID
ORDER BY PTS DESC
END;
然後我試圖通過執行下面的查詢使用SP:
DECLARE @team NCHAR,
@minutes DECIMAL
EXECUTE extrapstats @team = 'OKC', @minutes = 35
SELECT *
當我這樣做,我會遇到這樣的消息:
Msg 263, Level 16, State 1, Line 5
Must specify table to select from.
我已經嘗試了不同的變化這一點,但沒有任何工作。我以爲SP指定了從哪個表中選擇數據。
任何想法?
您有一條聲明'SELECT *'懸在那裏。您沒有指定可供選擇的表格。因此錯誤信息。 –