Stored Procedure Problems
I am having problems with the following stored procedure.
Am trying to pass a parameter "@VariableSwitch" to determine which
code is returned. When passing the "ProgramTeams" this runs fine but with any other entry I get a blank recordset with the column names from the ("vwProgTeams"/ProgramTeams) and blank fields.
It only seems to execute the first SELECT statement nd disregards the parameter.
Is there a better way of doing this ???
'##############
CREATE PROCEDURE spXPAY(@VariableSwitch nvarchar(50),
@DeptID int,@MajorID int,@GradeID int,
@ProgTeamID int,@Current bit, @Active bit,
@PayID int, @YRvalue int, @MNTvalue int,
@StaffID int, @AccountName nvarchar(15),
@SchoolID int,@StatusID int)
AS
if (@VariableSwitch = 'ProgramTeams')
SELECT vwProgTeams.*
FROM dbo.vwProgTeams
WHERE (@SchoolID is null OR intSchoolID = @SchoolID) AND (@ProgTeamID is null OR lngProgTeamIDcnt = @ProgTeamID) AND (blnActive = 1)
else
if (@VariableSwitch = 'Departments')
SELECT tblDepartments.*
FROM tblDepartments
WHERE (@DeptID is null OR lngDeptIDcnt = @DeptID) AND (@MajorID is null OR lngMajorDeptID = @MajorID)
else
if (@VariableSwitch = 'DeptSchools')
SELECT vwDeptSchools.*
FROM vwDeptSchools
WHERE (@DeptID is null OR lngDeptIDcnt = @DeptID)
else
if (@VariableSwitch = 'Grades')
SELECT tblGrades.*
FROM tblGrades
WHERE (@GradeID is null OR lngGradeIDcnt = @GradeID)
else
if (@VariableSwitch = 'LectStaff')
SELECT vwShowLectStaff.*
FROM vwShowLectStaff
WHERE (@ProgTeamID IS NULL) AND (@Current IS NULL) OR (@ProgTeamID IS NULL) AND (blnCurrent = @Current) OR (@Current IS NULL) AND (lngProgTeamID = @ProgTeamID) OR (blnCurrent = @Current)
AND (lngProgTeamID = @ProgTeamID) AND (@Active is null OR blnActive = @Active)
ORDER BY txtSurname, txtForename
else
if (@VariableSwitch = 'PayMonths')
SELECT vwPayMonths.*
FROM vwPayMonths
WHERE (@PayID is null OR lngPayIDcnt = @PayID) AND (@YRvalue is null OR YEAR(dtmMonth) = @YRvalue) AND (@MNTvalue is null OR MONTH(dtmMonth) = @MNTvalue)
ORDER BY dtmMonth
else
if (@VariableSwitch = 'PayrollList')
SELECT DISTINCT lngDepartmentID, txtDeptName
FROM vwAdvHours
else
if (@VariableSwitch = 'Staff')
SELECT vwStaff.*
FROM vwStaff
WHERE (@Current is null OR blnCurrent = @Current) AND (@Active is null OR blnActive = @Active) AND (@StaffID is null OR lngStaffIDcnt = @StaffID) AND (@AccountName is null OR txtAccountName = @AccountName)
ORDER BY txtSurname, txtForename
else
if (@VariableSwitch = 'Status')
SELECT tblStatus.*
FROM tblStatus
WHERE (@StatusID is null OR lngStatusIDcnt = @StatusID)
GO
'##############
|