declare @bussHallId nvarchar(255)= '2,3' declare @strWhere nvarchar(255)= '' declare @strMain nvarchar(500) if(@bussHallId is not null) set @strWhere ...
declare @bussHallId nvarchar(255)= '2,3' declare @strWhere nvarchar(255)= '' declare @strMain nvarchar(500) if(@bussHallId is not null) set @strWhere = @strWhere + ' and bh.ID in ('+@bussHallId+')' set @strMain = ' select * from T_BussHall bh where 1 =1 ' +@strWhere exec(@strMain)