locked
SQL error: "The multi-part identifier "table1.ID" could not be found" RRS feed

  • Question

  • User-1651604128 posted

    Hi,

    I have this SQL statement converted from an vb.net classic app to mvc C# web app,

    SELECT CASE WHEN table1.ID is not null then tabl2.PLA_NAME + ', ' + table1.D_ID + ', ' + table1.ID else table2.A_NAME + ', ' + table1.D_ID END table3.A_ID, table3.ID, cast([table3].[A_ID] as nvarchar) + cast([table3].[ID] as nvarchar) FROM table1 INNER JOIN (table3 INNER JOIN table2 ON table3.A_ID = table2.A_ID) ON table1.ID = table3.ID ORDER BY table2.A_NAME, table1.D_ID, table1.ID

    the above code works on the vb.net application, but I got compile time error when run it in sql server management studio

    "The multi-part identifier "table1.ID" could not be found" on each table highlighted in red above.

    Appreciate any input, thanks a lot,

    Edit, after some searching, found this solution: https://radacad.com/fixing-the-error-the-multi-part-identifier-could-not-be-bound-in-join-statements

    but I still can not fix my above codes, any help is appreciated,

    Friday, August 7, 2020 12:25 AM

Answers

  • User197322208 posted

    SELECT CASE WHEN table1.ID is not null then tabl2.PLA_NAME + ', ' + table1.D_ID + ', ' + table1.ID else table2.A_NAME + ', ' + table1.D_ID END table3.A_ID, table3.ID, cast([table3].[A_ID] as nvarchar) + cast([table3].[ID] as nvarchar) FROM table1 INNER JOIN (table3 INNER JOIN table2 ON table3.A_ID = table2.A_ID) ON table1.ID = table3.ID ORDER BY table2.A_NAME, table1.D_ID, table1.ID

    Try to give a name to 

    (table3 INNER JOIN table2 ON table3.A_ID = table2.A_ID)

    and make the inner join on this name instead ofn

    (table3 INNER JOIN table2 ON table3.A_ID = table2.A_ID) ON table1.ID = table3.ID

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 7, 2020 8:43 AM