2012-10-29 55 views
1

我工作的SQL Server中的過程:更新程序

我新的SQL Server &上我得到這個錯誤:

Must declare the scalar variable "@Course_Name"

我的程序是:

USE [Hyaline management System] 
GO 

SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 

CREATE PROCEDURE [dbo].[GetUpdateCourseID] 
@CourseID int 
AS 
BEGIN 

SET NOCOUNT ON; 
Update Course SET 
    Course_Name = @Course_Name, 
    Course_Duration = @Course_Duration 
where CourseID = @CourseID; 

END 

有人可以指點我哪裏出錯了嗎?和解決方案?

回答

3

看來,你缺少一些參數。既然你正在做的Course_NameCourse_DurationUPDATE,你可能需要將它們傳遞到存儲過程:

USE [Hyaline management System] 
GO 

SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 

CREATE PROCEDURE [dbo].[GetUpdateCourseID] 
    @CourseID int, 
    @Course_Name varchar(50),  -- change to the proper datatype 
    @Course_Duration varchar(100) -- change to the proper datatype 
AS 
BEGIN 

SET NOCOUNT ON; 

    UPDATE Course 
    SET Course_Name = @Course_Name, 
     Course_Duration = @Course_Duration 
    WHERE CourseID = @CourseID; 

END 
+0

謝謝bluefeet。你節省了我的時間。 – Rashid

+0

@ user1783853樂意提供幫助,如果答案有幫助,請務必通過左側的複選標記接受。這將有助於未來的訪問者,你將從接受中獲得聲望。 :) – Taryn

1
CREATE PROCEDURE [dbo].[GetUpdateCourseID] 
    @CourseID int, 
    @Course_Name varchar(max), 
    @Course_Duration int -- just a guess, minutes as an int? 
AS 
SET NOCOUNT ON; 
Update Course 
    SET Course_Name = @Course_Name, 
     Course_Duration = @Course_Duration 
WHERE CourseID = @CourseID; 
GO 

它說

Must declare the scaler variable "@Course_Name"

因爲你還沒有宣佈它。它看起來像你希望該變量作爲SP的輸入,所以你需要在"AS"導入正文部分之前將其添加到參數部分。

p/s - 請剪切並粘貼錯誤消息。這個錯誤是可以理解的,但如果您提供的是正確的,則其他人可以更容易在Google上搜索。這個應該有標量(a)不是定標器