Within a SQL query or stored procedure, multiple database tables can be referenced. The full database name just needs to be specified in the query.
SELECT *
FROM Appointment a
INNER JOIN TableLog.dbo.Appointment al ON al.appointmentid=a.appointmentid
WHERE a.appointmentid = @appointmentid