我写了一个存储过程:
ALTER PROCEDURE [dbo].[GetBRs_Pager]
@PageIndex INT
,@PageSize INT
,@SupId INT
,@RecordCount INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SELECT ROW_NUMBER()
OVER (
ORDER BY [tblBR].[ID] ASC
) AS RowNumber
,[tblBR].[ID]
,[tblBR].[BRName]
,[tblBR].[SupervisorId]
,[tblSupervisor].[SupervisorName]
,[tblBR].[BRCode]
,[tblBR].[BRMobile]
,[tblBR].[BRTypeId]
,[tblType].[TypeName]
,[tblBR].[BRImageUrl]
INTO #Results
FROM [tblBR]
INNER JOIN [tblType]
ON [tblBR].[BRTypeId] = [tblType].[ID]
INNER JOIN [tblSupervisor]
ON [tblBR].[SupervisorId] = [tblSupervisor].[ID]
where [tblBR].[Active] = 1
and [tblBR].[SupervisorId]=@SupId
SELECT @RecordCount = COUNT(*)
FROM #Results
SELECT * FROM #Results
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #Results
END
现在我想修改查询如下
if(@supId != 0) then where [tblBR].[Active] = 1
and [tblBR].[SupervisorId] = @SupId else [tblBR].[Active] = 1
怎么做?任何帮助我的人都非常感谢。提前致谢。