正文部分
写个存储过程的吧,简单的写法如下:
代码语言:javascript复制
drop procedure getTopUsers;
create procedure getTopUsers (IN filter_cond NVARCHAR(200)) as
begin
vUsers = SELECT DISTINCT user_name, creator FROM USERS;
if (:filter_cond is NULL) then
TopUsers = select TOP 5 user_name FROM :vUsers;
else
tTopUsers = APPLY_FILTER(:vUsers, :filter_cond);
TopUsers = SELECT TOP 5 user_name FROM :tTopUsers;
end if;
SELECT user_name FROM :TopUsers;
end;
call getTopUsers ('CREATOR != ''SYS'' ');
call getTopUsers (NULL);