title: SQL Server : reset variable value
body: <p>I am writing a query to get data from each DBO on my master.</p>
  
  <p>The query is similar to</p>
  
  <pre><code>DECLARE @variable1 INT
  DECLARE @variable2 INT
  
  SET @variable1 = (SELECT column1 
                    FROM database1.dbo.Table_name1 
                    WHERE column1 = value)
  SET @variable2 = (SELECT column2 
                    FROM database1.dbo.Table_name2 
                    WHERE column2 = value)
  
  SELECT @variable1/@variable2 AS MyIndex
  UNION ALL
  SET @variable1 = (SELECT column1 
                    FROM database2.dbo.Table_name1 
                    WHERE column1 = value)
  SET @variable2 = (SELECT column2  
                    FROM database2.dbo.Table_name2 
                    WHERE column2 = value)
  SELECT @variable1/@variable2 AS MyIndex
  </code></pre>
  
  <p>However I get the following error</p>
  
  <blockquote>
    <p>Incorrect syntax near the keyword 'SET'.</p>
  </blockquote>
  
  <p>on the line where I reset the <code>@variable1</code> value.</p>
  
  <p>Any help, please?</p>