I think you may have to create an xref table.Consider the followingcreate table #A (AID int not null,Report Varchar(30) null)create table #B (BID int not null,Report Varchar(30) null)insert into #Aselect 1, 'End of Day Accounts'union all select 2, 'End of Month Accounts'insert into #Bselect 1, 'End of Day Account - 01/01/09'union allselect 2, 'End of Day Account - 01/02/09'union allselect 3, 'End of Day Account - 01/03/09'union allselect 4, 'Accounts Reconcile'union allselect 5, 'End of Month Accounts 01/31/09'union allselect 6, 'End of Month Accounts 02/31/09'union allselect 7, 'Group Activities'select * from #aselect * from #bselect distinct A.report as reportfrom #A Ajoin #B B on A.report = Left(B.report,len(A.report))union allselect B.report as Reportfrom #b B left join #a A on A.report = Left(B.report,len(A.report))where A.report is null
Results:Select of table #A-------------------1 End of Day Accounts2 End of Month AccountsSelect of table #B-------------------1 End of Day Account - 01/01/092 End of Day Account - 01/02/093 End of Day Account - 01/03/094 Accounts Reconcile5 End of Month Accounts 01/31/096 End of Month Accounts 02/31/097 Group Activitiesfinal select-------------------End of Month AccountsEnd of Day Account - 01/01/09End of Day Account - 01/02/09End of Day Account - 01/03/09Accounts ReconcileGroup ActivitiesAs you see in the final select you do not get "End of Day Accounts" because in table B it's "End of Day Account - Date" (no S at the end of account).So you can't really say if A is a subset of B then use it and still get your desired results. So you need to either have more explicit selection criteria or you need a cross reference table that shows which reports should be grouped together.I'd use a cross reference table.Please let me know if I misunderstand something here.____________________________________________________An infinite universe is the ultimate cartesian product.