DECLARE _Sql Nvarchar(100);
DECLARE LSID INT;
DECLARE UID INT;
...
-- 必须拿CONCAT合并,不然用+会变成INT值
IF LSID>=1 THEN
SET @_Sql=CONCAT(@_Sql,' AND L.LSID=',LSID);
END IF;
IF UID>=1 THEN
SET @_Sql=CONCAT(@_Sql,' AND U_FROM.UID=',UID);
END IF;
PREPARE ex FROM @_Sql;
EXECUTE ex;
DEALLOCATE PREPARE ex;