我有一個存儲過程是這樣的:明確SQL存儲過程?
IF @Active=0
select @rowCount=(select count(1) from [table] WHERE (GETDATE() BETWEEN StartTime AND EndTime) AND [email protected]
IF @Active=1
select @rowCount=(select count(1) from [table] WHERE NOT(GETDATE() BETWEEN StartTime AND EndTime) AND [email protected]
有沒有什麼辦法,使報表更加清晰?這樣
我做分頁:
參數:
@pageNum AS BIGINT,
@pageSize AS BIGINT,
@Active AS INT,
@RowCount AS INT OUTPUT
,其餘:
IF @Active=0
BEGIN
WITH K AS
( - SELECT [Id]
FROM [table]
WHERE not(GETDATE() BETWEEN StartTime AND EndTime) AND [email protected] ORDER BY [Id]
OFFSET (@pagenum - 1) * @pagesize ROWS FETCH NEXT @pagesize ROWS ONLY
)
SELECT T.[Id],T.[Name]
FROM [table]
AS T
INNER JOIN K
ON T.Id = K.Id
ORDER BY T.Id;
select @rowCount=(select count(1) from [table] WHERE not(GETDATE() BETWEEN StartTime AND EndTime) AND [email protected]
END
IF @Active=1
BEGIN
WITH K AS
(
SELECT [Id]
FROM [table]
WHERE (GETDATE() BETWEEN StartTime AND EndTime) AND [email protected]
ORDER BY [Id]
OFFSET (@pagenum - 1) * @pagesize ROWS FETCH NEXT @pagesize ROWS ONLY
)
SELECT T.[Id],T.[Name]
FROM [table]
AS F
INNER JOIN K
ON T.Id = K.Id
ORDER BY T.Id;
select @rowCount=(select count(1) from [table] WHERE (GETDATE() BETWEEN StartTime AND EndTime) AND [email protected] END
和存儲過程看起來很長..... 所以我想知道是否有更好的方法來使它更好
是鉅細無遺的兩種可能的罪名 - 即是它的意思是,如果你用'一旦調用這個@ Active'設置爲0,再次設置爲1,並將結果相加在一起,如果這兩個結果的總和與'select [COUNT(*)from [table]''相同?因爲目前情況並非如此。 –