title: multi part identifier could not be bound
body: <p>I was trying this code to get the database related information.</p>
  
  <p>the script is---</p>
  
  <pre><code>DECLARE @USER_Name SYSNAME
  DECLARE @Database_Name VARCHAR(255)
  DECLARE @SQLQRY VARCHAR(2000)
  
  DECLARE Database_Cursor CURSOR
  FOR
  SELECT '[' + NAME + ']' AS NAME
  FROM master.dbo.sysdatabases
  WHERE NAME IN ('Aaskiran')
  ORDER BY NAME
  
  OPEN Database_Cursor
  
  FETCH NEXT
  FROM Database_Cursor
  INTO @Database_Name
  
  WHILE @@FETCH_STATUS = 0
  BEGIN
      PRINT 'Database:' + @Database_Name
  
      EXECUTE (
              'SELECT Type, COUNT(*) As Objects FROM
      ' + @Database_Name + '.dbo.sysobjects
      GROUP BY Type ORDER BY Type'
              )
  
      EXECUTE (
              'SELECT name As Table_Name FROM
      ' + @Database_Name + '.dbo.sysobjects
       WHERE type=''U'' ORDER BY name'
              )
  
      EXECUTE (
              'SELECT name As Stored_Proc_Name FROM
      ' + @Database_Name + '.dbo.sysobjects
       WHERE type=''P'' ORDER BY name'
              )
  
      DECLARE @Table_Name VARCHAR(255)
  
      EXECUTE (
              'DECLARE Table_Cursor CURSOR FOR SELECT name, USER_NAME(uid) FROM
      ' + @Database_Name + '.dbo.sysobjects
      WHERE type=''U'' ORDER BY name'
              )
  
      OPEN Table_Cursor
  
      FETCH NEXT
      FROM Table_Cursor
      INTO @Table_Name,
          @User_Name
  
      SET @SQLQRY = 'SELECT 
                         SUM (row_count) 
                     FROM sys.dm_db_partition_stats 
                     WHERE
                         object_id=OBJECT_ID(' + @Database_Name + '.[' + @User_Name + '].[' + @Table_Name + ']) 
                         AND (index_id=0  or index_id=1)'
  
      WHILE @@FETCH_STATUS = 0
      BEGIN
          EXECUTE (@SQLQRY)
  
          --EXECUTE('SELECT COUNT(*) AS ['+@Table_Name+'_Rows_Count] FROM '+@Database_Name+'.  ['+@User_Name+'].['+@Table_Name+']')
          --print('SELECT COUNT(*) AS ['+@Table_Name+'_Rows_Count] FROM '+@Database_Name+'.['+@User_Name+'].['+@Table_Name+']')
          FETCH NEXT
          FROM Table_Cursor
          INTO @Table_Name,
              @User_Name
      END
  
      CLOSE Table_Cursor
  
      DEALLOCATE Table_Cursor
  
      FETCH NEXT
      FROM Database_Cursor
      INTO @Database_Name
  END
  
  CLOSE Database_Cursor
  
  DEALLOCATE Database_Cursor
  </code></pre>
  
  <p>but i am getting an error that </p>
  
  <blockquote>
    <p>Msg 4104, Level 16, State 1, Line 1
    The multi-part identifier "AasKiran.##MS_PolicyEventProcessingLogin##.AADetails" could not be bound.</p>
  </blockquote>
  
  <p>I have googled about this error but most of the links are on joins. I am not getting the issue in my query as i had also not used any alias or doing any sort of join.</p>