title: Passing database name as variable to SQL from C#. Is it possible?
body: <p>I've 2 tables having exactly same columns. But they are stored in Database1 and Database2 (on same server). Can i pass database name as variable? For example:</p>
  
  <pre><code>                        SELECT  [SomeValue]
                          FROM    [Database2].[dbo].[Klienci]
  
                          SELECT  [SomeValue]
                          FROM    [Database1].[dbo].[Klienci]
  </code></pre>
  
  <p>Is there a way to pass whole [FROM] as @variable thru following code in C#:</p>
  
  <pre><code>            SqlCommand sqlQuery = new SqlCommand(preparedCommand, varConnection);
              sqlQuery.Prepare();
              sqlQuery.Parameters.AddWithValue("@varDatabase", varDatabase);
  </code></pre>
  
  <p>Where @varDatabase would hold database name and/or table name ie. [Database1].[dbo].[Klienci] in one format or another.</p>
  
  <p>I'm talking about C# 3.5 / MSSQL 2005/2008.</p>