Last post Aug 07, 2020 08:43 AM by ignatandrei
Member
366 Points
2214 Posts
Aug 07, 2020 12:25 AM|Peter Cong|LINK
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,
All-Star
120166 Points
27994 Posts
Moderator
MVP
Aug 07, 2020 08:43 AM|ignatandrei|LINK
Peter Cong 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
Member
366 Points
2214 Posts
SQL error: "The multi-part identifier "table1.ID" could not be found"
Aug 07, 2020 12:25 AM|Peter Cong|LINK
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,
All-Star
120166 Points
27994 Posts
Moderator
MVP
Re: SQL error: "The multi-part identifier "table1.ID" could not be found"
Aug 07, 2020 08:43 AM|ignatandrei|LINK
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