前面不变,反正就这么一个意思,语法可能有问题(where的拼接以及最后SQL的)
begin
DECLARE where_ CHAR(100);
set where_='1=1'
if (sid<>'') then
set where_=where_+'userid='+sid
else if (sname<>'') then
set where_=where_+'USENAME='+sname
end if;
SELECT * FROM USERS WHERE where_
end
MYSQL的存储过程写不来
SELECT * FROM USERS WHERE 1=1 ${IF(LEN(SID)==0,"AND 1=1","AND USERID='"+SID+"'")} ${IF(LEN(sname)==0,"AND 1=1","AND USENAME='"+sname+"'")}