title: SELECT case using a variable which can be set based on a parameter
body: <p>I'd like to select a particular value from a table while using an information from another database that is set based on a current database's value. </p>
  
  <p>So a select case to find the operator code and set the DB path.. then use the same path and collate the result. </p>
  
  <pre><code>DECLARE @DB varchar (1000)
  
  CASE 
  WHEN @Operator= 1 THEN SET @DB = '{SERVERNAME\ENTITY\DBNAME}'
  WHEN @Operator= 2 THEN SET @DB = '{SERVERNAME2\ENTITY2\DBNAME2}'
  WHEN @Operator= 3 THEN SET @DB = '{SERVERNAME3\ENTITY3\DBNAME3}'
  
  Select transItem_item collate SQL_Latin1General_CI_AS
  FROM Group_Transactions
  INNER JOIN @DB.Table_Trans
  ON (transItem.item_id collate SQL_Latin1General_CI-AS = Table_Trans.item_id)
  Where ---Condition
  </code></pre>