SQL Server: Invalid Column Name

前端 未结 13 988
一个人的身影
一个人的身影 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

    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
    

提交回复
热议问题