日期:2014-05-17 浏览次数:20627 次
declare @role_type int select @role_type=role_type from accounts_userroles where user_id=1 if @role_type=1 begin select * from project end else begin select * from project2 where userid=1 end
------解决方案--------------------
DECLARE @i INT SET @i = 1 --可以修改为2 SELECT * FROM ( SELECT * , 1 AS role_type FROM project UNION ALL SELECT project2.* , 2 AS role_type FROM project2 INNER JOIN accounts_userroles C ON C.USER_ID = project2.USER_id ) B INNER JOIN accounts_userroles A ON A.role_type = B.role_type WHERE A.user_id = @i