title: SQL Declare Variables
body: <p>Can anyone check on my statement...</p>
  
  <pre><code>DECLARE @tblName varchar(MAX), 
          @strSQL varchar(MAX)
  
  SET @tblName ='SELECT DISTINCT o.name as TableName 
                   FROM sysobjects o 
                   JOIN sysindexes x on o.id = x.id  
                  WHERE o.name LIKE ''%empty%'''  
  
  SET @strSQL = 'INSERT INTO @tblName VALUES(''trylng'', ''1'')'
  EXEC (@strSQL)
  </code></pre>
  
  <p>my error is...</p>
  
  <blockquote>
    <p>Msg 1087, Level 15, State 2, Line 1<br>
    Must declare the table variable "@tblName".</p>
  </blockquote>