title: Execute same query two different databases using stored procedure
body: <p>How can I execute the same query using two different databases within the same server using stored procedure all based on a variable(parameter)?</p>
  
  <p>This has to be done in a stored procedure because of the way I'm using it. The information are stored in the same table names on both databases. I need the results to be dynamic based on a variable. If X variable is entered it needs to read from databaseA but if Y is entered it needs to read from databaseB.</p>
  
  <p>All I have right now is a working query that will work is the dbo is changed each time. I've spent a lot of time searching for an answer, but I am unable to find anything. Can anyone help me get started?</p>