Click here to Skip to main content
15,923,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello programmers, got a few problems here. As you see I am trying to create A procedure (New on this stuff) but got an error saying

Msg 102, Level 15, State 1, Procedure GetAllCoursesAndCategories, Line 3<br />
Incorrect syntax near '@CourseCatID'.<br />
Msg 137, Level 15, State 2, Procedure GetAllCoursesAndCategories, Line 18<br />
Must declare the scalar variable "@Year".

Sir what is the problem regarding that? Please help.. Thanks and more power
SQL
CREATE PROCEDURE GetAllCoursesAndCategories
        @Year varchar(128)
        @CourseCatID int
AS
BEGIN
    Select Crse.CourseName, CrseYr.CourseCode ,CrseYr.CourseDuration
       from TrainingPlanTemplate temp
    Inner Join Course Crse On
    temp.CourseID = Crse.CourseID
    Inner Join CourseCategory CrseCat On
    temp.CourseCatID = CrseCat.CourseCatID
    Inner Join CourseYear CrseYr On
    temp.Year = CrseYr.Year
    Inner Join CourseCatYear CrseCtYr On
    temp.Year = CrseCtYr.Year

    Where
    temp.Year = @Year And
    temp.CourseCatID = @CourseCatID
END
GO
Posted

I think you forgot to put a comma on the second line. Change lines 1,2 & 3 with the following:

SQL
CREATE PROCEDURE GetAllCoursesAndCategories
        @Year varchar(128),
        @CourseCatID int
 
Share this answer
 
Comments
Muralikrishna8811 6-Oct-11 0:11am    
Nice
----my 5
SQL
CREATE PROCEDURE GetAllCoursesAndCategories
        @Year varchar(128)
        @CourseCatID int
AS



replace the above code with this one

SQL
CREATE PROCEDURE GetAllCoursesAndCategories
       {
        @Year varchar(128),
        @CourseCatID int
       }
AS
 
Share this answer
 
v2
Hi,

You can learn much about procedures in sql server through these links

check this link

http://msdn.microsoft.com/en-us/library/aa258259(v=sql.80).aspx


All the Best
 
Share this answer
 
Hello Friend..

Your Syntax near declaration part is wrong, that's why you got this error..

you have to declare a parameter in store procedure but when you want to declare more then one parameter at that time you have to saprate it with "," (comma) so its a right syntax to declare a parameter in store procedure.

like this ..
SQL
--if it is one then no need to apply  , to it
@ID INT


SQL
--but if it is more then one then declare like this..

@ID INT,
@FirstName NVARCHAR(20),
@LastName NVARCHAR(20)


But also not that when we declare a parameter and its more then one then at that time we have to apply "," but at that time it also care that at the last parameter you need not to put the "," like in above example i will put comma at @ID and @FirsName but not at @LastName

so tack care for it..

and in you procedure you have to put comma at @Year parameter so your error will be solved like this...

SQL
CREATE PROCEDURE GetAllCoursesAndCategories
        @Year varchar(128),
        @CourseCatID int



and for more information on store procedure please refer this links..

Overview of SQL Server Stored Procedure[^]

http://msdn.microsoft.com/en-us/library/aa258259%28v=sql.80%29.aspx[^]

http://msdn.microsoft.com/en-us/library/ms345415.aspx[^]
 
Share this answer
 
v2
I think u should try this one->

SQL
CREATE PROCEDURE GetAllCoursesAndCategories
(
        @Year varchar(128),
        @CourseCatID int
)
AS
BEGIN
    Select Crse.CourseName, CrseYr.CourseCode ,CrseYr.CourseDuration
       from TrainingPlanTemplate temp
    Inner Join Course Crse On
    temp.CourseID = Crse.CourseID
    Inner Join CourseCategory CrseCat On
    temp.CourseCatID = CrseCat.CourseCatID
    Inner Join CourseYear CrseYr On
    temp.Year = CrseYr.Year
    Inner Join CourseCatYear CrseCtYr On
    temp.Year = CrseCtYr.Year
 
    Where
    temp.Year = @Year And
    temp.CourseCatID = @CourseCatID
END
GO
 
Share this answer
 
v2
SQL
CREATE PROCEDURE GetAllCoursesAndCategories
(
        @Year varchar(128), // here
        @CourseCatID int
)
AS



put , comma in your code
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900