I am trying to run the below code but run into the error:
Multi-part Identifier could not be bound
I think it is due to trying to access a database table from a separate database but it is on the same server. Any ideas?
SELECT DISTINCT
@ActiveStudents2 = COUNT([ActivityHistory].[dbo].[tblActivityCounts].[id])
FROM
dbo.tblSchools
INNER JOIN
dbo.tblStudentSchool ON dbo.tblSchools.schoolid = dbo.tblStudentSchool.schoolid
INNER JOIN
dbo.tblStudentPersonal ON dbo.tblStudentSchool.id = dbo.tblStudentPersonal.id
WHERE
dbo.tblStudentSchool.schoolid IN (@tempschoolid)
AND tblStudentSchool.graduationyear IN (SELECT Items
FROM FN_Split(@gradyears, ','))
AND ([ActivityHistory].[dbo].[tblActivityCounts].[datetimechanged] >= @datefrom
AND [ActivityHistory].[dbo].[tblActivityCounts].[datetimechanged] <= @dateto)
The error occurs when I try to access the tblActivityCounts table in the Activity History database which is a separate database. I even try running this as the sa and it doesn't work. There aren't any spelling errors. Any help is appreciated. Thank you!