title: Msg 137, Must declare the scalar variable
body: <pre><code>Declare @SKUCode1 varchar(30), @SKUCode2 varchar(30), @SKUCode3 varchar(30),
          @SKUCode4 varchar(30), @SKUCode5 varchar(30), @SKUCode6 varchar(30),
          @SKUCode7 varchar(30), @SKUCode7 varchar(30), @SKUCode8 varchar(30),
          @SKUCode10 varchar(30), @Temp_SKU varchar(30), @SKUCodeS varchar(30),
          @sp1 nvarchar(max),@Index int
  
  Set @SKUCodeS = 'SKUCode'
  Set @Index = 0
  
  While @Index &lt; 10   
  Begin
      Set @Index = @Index + 1  
  
      Select @Temp_SKU = SKUCode  
      From dbo.UDA_Order  
      Where Areaname = 'LMC-TYRE BUILDING'
  
      Set @sp1 = 'Set'+' '+ @SKUCodeS+CONVERT(varchar,@Index)+' '+'='+' '+'@Temp_SKU'  
  
      Exec sp_executesql @sp1  
  End
  </code></pre>
  
  <p>This is throwing error </p>
  
  <blockquote>
    <p>Msg 137,Level 15, State 2, Line 1<br>
    Must declare the scalar variable "@Temp_SKU"</p>
  </blockquote>
  
  <p>I have no clue why it is happening.</p>
  
  <p>Please help.</p>