34,575
社区成员
发帖
与我相关
我的任务
分享
sql = sql + ' where 1=1';
if (s_Dep is not null)
{
sql = sql + ' and DepID='+@s_Dep;
}
exec (@sql)
像你这样,然后再用exec (@sql)或者sp_exectesql来执行动态语句了。where 1=1
and DepID = case when
@s_Dep is not null
And @s_Dep != ''
then @s_Dep
else DepID end
GROUP BY ……
where 1=1
And @s_Dep is not null
and DepID=@s_Dep
GROUP BY ……
……
where 1=1
and DepID = case when
@s_Dep is not null
then @s_Dep
else DepID end
GROUP BY ……