title: constant in query of stored procedure
body: <p>This is the code from stored procedure of SQL server. I have declared constant @other_db to use it in queries. For simple queries i am able to do as mentioned below.</p>
  
  <pre><code>DECLARE @other_db VARCHAR(50)
  
      SET @other_db = 'BABMwork8_22_1210_0012'
  
      UPDATE BABMwork8_22_1210_0012.dbo.concessions   SET double_ones = '' WHERE double_ones = 'Yes'  
  
      EXEC('UPDATE @other_db.dbo.concessions SET double_ones = '+''+' WHERE double_ones = '+'Yes')
  </code></pre>
  
  <p>But for the query mentioned below, i want to use constant @other_db to replace the value of BABMwork8_22_1210_0012. </p>
  
  <pre><code>UPDATE concessions SET double_ones = 'Yes'
                     WHERE (concession IN(SELECT concession FROM BABMwork8_22_1210_0012.dbo.concessions WHERE
                                          (manuell_archive_delete! = 'Delete' OR  manuell_archive_delete IS NULL) AND 
                                          (double_action = 'ok_invoice' OR double_action is NULL)) 
                            OR concession IN(SELECT Concession FROM BABMwork8_22_1210_0012.dbo.invoicing WHERE 
                                          (can_invoiced is NULL OR can_invoiced != 'No') AND
                                          (double_action = 'ok_invoice' OR double_action is NULL)))
                            AND (double_action = 'ok_invoice' OR double_action is NULL) 
                            AND (manuell_archive_delete! = 'Delete' OR  manuell_archive_delete IS NULL) AND
                                 source!= 'PARK'
  </code></pre>
  
  <p>Eventhough i tried with EXEC it is getting complicated. I have couple of queries if there any simple method to use constant.</p>
  
  <p>Thanks for your help!</p>