SQL Server: Invalid Column Name

前端 未结 13 845
一个人的身影
一个人的身影 2020-12-22 23:49

I am working on modifying the existing SQL Server Stored Procedure. I added two new columns to the table and modified the stored procedure as well to select these two column

相关标签:
13条回答
  • 2020-12-22 23:56

    Whenever this happens to me, I press Ctrl+Shift+R which refreshes intellisense, close the query window (save if necessary), then start a new session which usually works quite well.

    0 讨论(0)
  • 2020-12-22 23:56
    • Refresh your tables.
    • Restart the SQL server.
    • Look out for the spelling mistakes in Query.
    0 讨论(0)
  • 2020-12-22 23:56

    I noted that, when executing joins, MSSQL will throw "Invalid Column Name" if the table you are joining on is not next to the table you are joining to. I tried specifying table1.row1 and table3.row3, but was still getting the error; it did not go away until I reordered the tables in the query. Apparently, the order of the tables in the statement matters.

    +-------------+    +-------------+    +-------------+    
    | table1      |    | table2      |    | table3      |    
    +-------------+    +-------------+    +-------------+    
    | row1 | col1 |    | row2 | col2 |    | row3 | col3 |    
    +------+------+    +------+------+    +------+------+    
    | ...  | ...  |    | ...  | ...  |    | ...  | ...  |    
    +------+------+    +------+------+    +------+------+    
    
    
    SELECT * FROM table1, table2 LEFT JOIN table3 ON row1 = row3; --throws an error
    
    SELECT * FROM table2, table1 LEFT JOIN table3 ON row1 = row3; --works as expected
    
    0 讨论(0)
  • 2020-12-23 00:01

    Intellisense is not auto refreshed and you should not fully rely on that

    0 讨论(0)
  • 2020-12-23 00:04
    There can be many things:
    First attempt, make a select of this field in its source table;
    Check the instance of the sql script window, you may be in a different instance;
    Check if your join is correct;
    Verify query ambiguity, maybe you are making a wrong table reference
    Of these checks, run the T-sql script again
    
    [Image of the script SQL][1]
      [1]: https://i.stack.imgur.com/r59ZY.png`enter code here
    
    0 讨论(0)
  • 2020-12-23 00:09

    I just tried. If you execute the statement to generate your local table, the tool will accept that this column name exists. Just mark the table generation statement in your editor window and click execute.

    0 讨论(0)
提交回复
热议问题