i am using a CTE expression, as part of a script that copy data between diffrent db's.in the middle of the script i have the following code :;WITH cteGetNewVSOldGroup (oldGroupId, newGroupId) AS ( select t1.oldGroupId,t2.id from #tblGroups t1 Inner join [DB1].[dbo].Dyn_Group t2 on t1.name=t2.name where t2.CompanyRef=@newCompanyRef and t2.UserRef=@newUserId ) INSERT INTO [DB1].[dbo].[Dyn_Group2] ([GrandParent] ,[Parent] ,[Child]) select t2.newGroupId,t3.newGroupId,t4.newGroupId from #tblGroup2Group t1 inner join cteGetNewVSOldGroup as t2 on t1.GrandParent=t2.oldGroupId inner join cteGetNewVSOldGroup as t3 on t1.Parent=t3.oldGroupId inner join cteGetNewVSOldGroup as t4 on t1.Child=t4.oldGroupId
i get an error : Invalid object name 'cteGetNewVSOldGroup'.any idea?thanksPeleg