title: Must declare the scalar variable with SELECT statement
body: <p>I have the following statement:</p>
  
  <pre><code>DECLARE @Nr_Karton int;
  
  SELECT @Nr_Karton = ISNULL(MAX(Nr), 1000)  FROM W_Karton;
  
  SET @Nr_Karton = @Nr_Karton + 1;
  
  INSERT INTO W_Karton (Container_ID, Nr, Beschrieb, CreationDate, Location) 
    VALUES ('1', @Nr_Karton, '', getDate(), 'Bösingen');
  </code></pre>
  
  <p>But I get the error:</p>
  
  <blockquote>
    <p>[SQL] SELECT @Nr_Karton = ISNULL(MAX(Nr), 1000)  FROM W_Karton</p>
    
    <p>[Err] 42000 - [SQL Server]Must declare the scalar variable "@Nr_Karton".</p>
  </blockquote>
  
  <p>How to get rid of the error?</p>