title: Error : Must declare the table variable "@RestoreList"
body: <p>I stuck with this error in my new littre project.</p>
  <p>Here the code :</p>
  <pre><code>                Cmd.Connection = Cnx;
                  Cmd.CommandText = &quot;DECLARE @command varchar(5000);&quot;;
                  Cmd.CommandText = &quot;DECLARE @RestoreList TABLE(DB_name VARCHAR(100), RS_name VARCHAR(100), RS_DateCloture DATETIME);&quot;;
                  Cmd.CommandText = &quot;SELECT @command = 'IF ''?'' IN (SELECT name FROM sys.databases WHERE HAS_DBACCESS(name) = 1 AND CASE WHEN state_desc = ''ONLINE'' THEN OBJECT_ID( QUOTENAME( name ) + ''.[dbo].[P_DOSSIER]'',''U'' ) END IS NOT NULL) BEGIN USE [?] SELECT DB_name = CAST(DB_NAME() AS VARCHAR(100)), RS_name = CAST(D_RaisonSoc AS VARCHAR(100)), RS_DateCloture = CAST((SELECT Max(v) FROM (VALUES ([D_FinExo01]), ([D_FinExo02]), ([D_FinExo03]),([D_FinExo04]),([D_FinExo05])) AS value(v)) AS DATETIME) FROM [?].[dbo].[P_DOSSIER] END';&quot;;
                  Cmd.CommandText = &quot;INSERT INTO @RestoreList EXEC sp_MSforeachdb @command;&quot;;
                  Cmd.CommandText = &quot;SELECT * FROM @RestoreList;&quot;;
  
                  SqlDataReader reader = Cmd.ExecuteReader();
  </code></pre>
  <p>If someone can tell what is wrong ?</p>