公众号:
SAP Technical
本文作者:
matinal
前言部分
大家可以关注我的公众号,公众号里的排版更好,阅读更舒适。
正文部分
写个存储过程的吧,简单的写法如下:
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);