I have an existing query from MS Access that I want to convert it to
SQL Server Stored Proc. My problem is on how to convert the WHERE
clause.
This is the query from MS Access:
SELECT SchYrSemCourseJoin.SchYrSemCourseID, Students.IDNo, [LastName]
& ", " & [FirstName] & " " & [MiddleName] AS Name,
Program.ProgramTitle, Program.ProgramDesc, SchYrSem.SchYr,
SchYrSem.Sem, SchYrSem.Year, SchYrSem.Section AS Section1,
Major.Major, Course.CourseCode, Course.CourseTitle, Course.Unit,
SchYrSemCourseJoin.Final, SchYrSem.SchYrSemID
FROM (Program INNER JOIN Students ON Program.ProgramID =
Students.ProgramID) INNER JOIN ((Major INNER JOIN SchYrSem ON
Major.MajorID = SchYrSem.MajorID) INNER JOIN (Course INNER JOIN
SchYrSemCourseJoin ON Course.CourseID = SchYrSemCourseJoin.CourseID)
ON SchYrSem.SchYrSemID = SchYrSemCourseJoin.SchYrSemID) ON
Students.IDNo = SchYrSem.IDNo
WHERE ((([LastName] & ", " & [FirstName] & " " &
[MiddleName])=[Forms]![Rating Report Dialog]![SubName]) AND
((SchYrSem.Year) Like IIf(IsNull([Enter Value]),"*",[Enter Value])));
This is a stored proc that I have currently created:
CREATE PROCEDURE dbo.Rating
@LastName nvarchar(50)
AS SELECT SchYrSemCourseJoin.SchYrSemCourseID, Students.IDNo,
[LastName] + ', ' + [FirstName] + ' ' + [MiddleName] AS Name,
Program.ProgramTitle, Program.ProgramDesc, SchYrSem.SchYr,
SchYrSem.Sem, SchYrSem.Year, SchYrSem.Section AS Section1,
Major.Major, Course.CourseCode, Course.CourseTitle, Course.Unit,
SchYrSemCourseJoin.Final, SchYrSem.SchYrSemID
FROM (Program INNER JOIN Students ON Program.ProgramID =
Students.ProgramID) INNER JOIN ((Major INNER JOIN SchYrSem ON
Major.MajorID = SchYrSem.MajorID) INNER JOIN (Course INNER JOIN
SchYrSemCourseJoin ON Course.CourseID = SchYrSemCourseJoin.CourseID)
ON SchYrSem.SchYrSemID = SchYrSemCourseJoin.SchYrSemID) ON
Students.IDNo = SchYrSem.IDNo
WHERE ((([LastName] + ', ' + [FirstName] + ' ' +
[MiddleName])=@LastName)) Return
GO
My problem is on how can I add the second criteria which is the Field
Year on my stored proc. The query above (MS Access) returns all the
records if the Parameter Enter Value is null.
Anyone know how to do this in stored proc? I want to create a stored
proc that will have the same results as the query above.
Thanks in advance.