34,587
社区成员
发帖
与我相关
我的任务
分享
select sum(total) from o where pp in (select id from p where pad=@p1)
union
select sum(total) from o where pp in (select id from p where pad2=@p2)
declare @i int
declare @j int
declare @sql varchar(8000)
SET @i = 1
SET @j = 2
set @sql ='select sum(total) from o where pp in (select id from p where pad ='+convert(varchar,@i)+' or pad2 = '+convert(varchar,@j)+')'
PRINT @sql
EXEC(@sql) --执行即可
select sum(total)
from o
where pp in (select id from p where pad = 1 or pad2 = 2)