存储过程中使用IF...ELSE报错 if (@commit_rs='all') and EnterpriseId in(select EnterpriseId from T_ConductResult) else and EnterpriseId in(select EnterpriseId from T_ConductResult where ConductId=@commit_rs) if (@playcount<>'0') and adid in (SELECT adid FROM T_Result group by adid having count(adid)>@playcount) )tt GROUP BY ADNAME,TYPENAME,CheckName,CheckEnterprise,IsSex,channelname
declare @sql nvarchar(max)
set @sql='select .......from.......'
if (@commit_rs='all')
set @sql=@sql+' and EnterpriseId in(select EnterpriseId from T_ConductResult)'
else
set @sql=@sql+' and EnterpriseId in(select EnterpriseId from T_ConductResult where ConductId='+@commit_rs+')'
if (@playcount<>'0')
set @sql=@sql+' and adid in (SELECT adid FROM T_Result group by adid having count(adid)>'+@playcount+')
)tt'
set @sql=@sql+'
GROUP BY ADNAME,TYPENAME,CheckName,CheckEnterprise,IsSex,channelname'
exec(@sql)
------解决方案--------------------