ODBC--Call Failed
[Microsoft][SQLServer Natrive Client 10.0][SQL Server]The multi-part identifier "ro.RoleID" could not be bound. (#4104) [Microsoft][SQL Server Native Client 10.0][SQL Server]The multi-part identifier "ro.RoleID" cound not be bound.(#4104)
The error repeats itself, just like that. The text is slightly different when I use the SQL Server driver instead of the Native Client but the reported error is the same.
The query I want to run is PermittedPrograms_qry. PermittedPrograms_qry should be a join of the dbo_sysPermissions_tbl table to AllProgramRoles_qry on AppID, RoleID and ProgramID. In this case, I am trying to find what programs are not permitted, so I need to do a Left Join. INNER JOIN works fine, no problem. Left Join works in some cases and not in others.
There is some weird problem joining to the dbo_sysRoles_tbl table. AllProgramRoles_qry works fine by itself but when the error happens it seems to point back to a problem in that query.
These joins work:
1 Left join, RoleID
2 left joins, programID and AppID, missing RoleID
3 INNER Joins
These joins do not work and result in the error I showed above:
all 3 left joins
2 Left Joins, RoleID, ProgramID, missing APPID left join
2 Left Joins, AppID and RoleID, missing ProgramID left join
Note that joining on RoleID by itself works okay.
I've tried this, using both the SQL Native Client driver and the SQL Server driver. I've also tried it in SQL 2008 mode (I have tried this with both COMPATIBILITY_LEVEL = 100) and 2012 mode(COMPATIBILITY_LEVEL = 110).
Below you will find the SQL code for the various joins I've described. Note that all ID fields are integers.
Thanks for any advice you may have.
The SQL for the AllProgramRoles_qry is here. Note the "ro." that appears in the error messages. This query works fine by itself, and in some combinations below.
Expand|Select|Wrap|Line Numbers
- SELECT pr.ProgramID, pr.AccessType, pr.AppID, ro.RoleID
- FROM dbo_sysPrograms_tbl AS pr, dbo_sysRoles_tbl AS ro
- WHERE (((pr.Menu_YN)=True));
all 3 left joins
Expand|Select|Wrap|Line Numbers
- SELECT apr.ProgramID, apr.AccessType, apr.AppID, apr.RoleID
- FROM AllProgramRoles_qry AS apr LEFT JOIN dbo_sysPermissions_tbl AS per ON (apr.AppID = per.AppID) AND (apr.ProgramID = per.ProgramID) AND (apr.RoleID = per.RoleID);
2 Left Joins, RoleID, ProgramID, missing APPID left join
Expand|Select|Wrap|Line Numbers
- SELECT apr.ProgramID, apr.AccessType, apr.AppID, apr.RoleID
- FROM AllProgramRoles_qry AS apr LEFT JOIN dbo_sysPermissions_tbl AS per ON (apr.RoleID = per.RoleID) AND (apr.ProgramID = per.ProgramID);
2 Left Joins, AppID and RoleID, missing ProgramID left join
Expand|Select|Wrap|Line Numbers
- SELECT apr.ProgramID, apr.AccessType, apr.AppID, apr.RoleID
- FROM AllProgramRoles_qry AS apr LEFT JOIN dbo_sysPermissions_tbl AS per ON (apr.AppID = per.AppID) AND (apr.RoleID = per.RoleID);
1 Left join, RoleID
Expand|Select|Wrap|Line Numbers
- SELECT apr.ProgramID, apr.AccessType, apr.AppID, apr.RoleID
- FROM AllProgramRoles_qry AS apr LEFT JOIN dbo_sysPermissions_tbl AS per ON apr.RoleID = per.RoleID;
Expand|Select|Wrap|Line Numbers
- SELECT apr.ProgramID, apr.AccessType, apr.AppID, apr.RoleID
- FROM AllProgramRoles_qry AS apr LEFT JOIN dbo_sysPermissions_tbl AS per ON (apr.AppID = per.AppID) AND (apr.ProgramID = per.ProgramID);
Expand|Select|Wrap|Line Numbers
- SELECT apr.ProgramID, apr.AccessType, apr.AppID, apr.RoleID
- FROM AllProgramRoles_qry AS apr INNER JOIN dbo_sysPermissions_tbl AS per ON (apr.RoleID = per.RoleID) AND (apr.AppID = per.AppID) AND (apr.ProgramID = per.ProgramID);
Expand|Select|Wrap|Line Numbers
- SELECT apr.ProgramID, apr.AccessType, apr.AppID, apr.RoleID, Nz([per].[RoleID],-1) AS Expr1
- FROM AllProgramRoles_qry AS apr LEFT JOIN dbo_sysPermissions_tbl AS per ON (apr.ProgramID = per.ProgramID) AND (apr.AppID = per.AppID)
- WHERE (((Nz([per].[RoleID],-1))<>[apr].[RoleID]));