if (len(@SalesName)>0) set @Condition = @Condition + ' and C.SalesName like ''%' + @SalesName + '%''' if (len(@CatalogCode)>0) set @Condition = @Condition + ' and D.CatalogCode like ''%' + @CatalogCode + '%''' if (len(@CatalogName)>0) set @Condition = @Condition + ' and D.CatalogName like ''%' + @CatalogName + '%''' if (len(@Condition)>0) set @Condition = substring(@Condition,5,len(@Condition)) --print @Condition exec sp_Paging N'',N''' as CheckBox, A.TargetID, A.TargetPeriod, Convert(varchar(10), B.BeginDate, 120) as BeginDate, Convert(varchar(10), B.EndDate, 120) as EndDate, C.SalesCode, C.SalesName, D.CatalogCode, D.CatalogName, E.OrgID, E.OrgName, F.OrgID as BranchOrgID, F.OrgCode as BranchOrgCode, F.OrgName as BranchOrgName, A.Amount, '' as DetailButton', N'ChlSalesTarget as A left outer join ChlSalesTargetPeriod as B on A.TargetPeriod=B.TargetPeriod left outer join ChlSales as C on A.Sales=C.SalesCode left outer join ChlItemCatalog as D on A.ItemCatalog=D.CatalogCode left outer join ChlOrg as E on A.OrgID=E.OrgID left outer join ChlOrg as F on C.BranchOrgID=F.OrgID', @Condition, N'A.TargetPeriod desc,C.SalesName,D.CatalogName', @PageIndex, @PageSize