关于存储过程中的IF 、Else的嵌套问题
BEGIN
DECLARE @sql NVARCHAR(2000)
IF(@RoleName = '管理员')
SET @sql = 'SELECT * FROM [CustomerServiceDemoDB_zcx].[dbo].[CustomServiceInfo] WHERE 1=1 '
IF(@CusName <> '')
SET @sql = @sql + ' AND CusName = '+CHAR(39)+ @CusName +CHAR(39)
ELSE IF(@EmpName <> '')
SET @sql = @sql + ' AND EmpName = '+CHAR(39)+ @EmpName +CHAR(39)
ELSE IF(@Type <> '')
SET @sql = @sql + ' AND Type = '+CHAR(39)+ @Type +CHAR(39)
ELSE IF(@Audit <> '')
SET @sql = @sql + ' AND Audit = '+CHAR(39)+ @Audit +CHAR(39)
ELSE
SET @sql = @sql + ' ORDER BY ServiceNumber DESC ';
ELSE IF(@RoleName = '经理')
SELECT * FROM CustomServiceInfo CSI, EmployeeInfo EI WHERE CSI.EmpID = EI.EmpID AND EI.AreaName = @AreaName AND EI.RoleName = '工程师' ORDER BY ServiceNumber DESC ;
ELSE IF(@RoleName = '工程师')
SELECT * FROM [CustomerServiceDemoDB_zcx].[dbo].[CustomServiceInfo] WHERE EmpID = (SELECT EmpID FROM EmployeeInfo WHERE UserID = @UserID) ORDER BY ServiceNumber DESC ;
END
ELSE IF(@RoleName = '工程师')
SELECT * FROM [CustomerServiceDemoDB_zcx].[dbo].[CustomServiceInfo] WHERE EmpID = (SELECT EmpID FROM EmployeeInfo WHERE UserID = @UserID) ORDER BY ServiceNumber DESC ;
END