title: How to use a variable within a Set @var = Select statement
body: <p>Why doesn't this work? (<strong>NOW SOLVED</strong>)
  </p>
  
  <pre><code>Declare @var1 Varchar(10)
  Set @var1 = 'Value 1'
  
  Declare @var2 Int
  Set @var2 = (Select [IntValue]
               From [TableOfValues]
               Where [StringValue] = @var1
              )
  
  Select @var1, [IntValue]
  
  From [TableOfValues]
  </code></pre>
  
  <p>But this does...</p>
  
  <pre><code>Declare @var1 Varchar(10)
  Set @var1 = 'Value 1'
  
  Declare @var2 Int
  Set @var2 = (Select [IntValue]
               From [TableOfValues]
               Where [StringValue] = 'Value 1'
              )
  
  Select @var1, [IntValue]
  
  From [TableOfValues]
  </code></pre>
  
  <p>I assume it's something to do with the query in the brackets running first, but how do I get my previously defined variable in there?  This is obviously a simplified version of a much bigger query.</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT:</strong> The above does work, but the variable in the real query was longer than 10 chars.  Silly mistake I know, but I've been staring at code all day.  Sorry to have wasted anyone's time.</p>