9
Views
1
Comments
Solved
What is wrong with my SQL query widget?
Question

Hello, guys...
I am facing an issue related to a SQL widget... I have the following SQL command:

SELECT {PerfilUser}.*, {User}.*,{Perfil}.[Id]
FROM ({User}
    Left JOIN {PerfilUser} FirstUser ON ({User}.[Id] = FirstUser.[UserId])),
     {Perfil}  Left JOIN {PerfilUser} SecondUser ON ({Perfil}.[Id] = SecondUser.[PerfilId])
WHERE ({User}.[Is_Active] = 1)
    AND ((((@PerfilUser_PerfilId <> 0)))) 
    
    AND ({User}.[Id] NOT IN (SELECT  {PerfilUser}.[UserId] FROM {PerfilUser} WHERE ({PerfilUser}.[PerfilId] = {Perfil}.[Id]) ))

However whenever I try to test the SQL I get the following error:

Database returned the following error: Error in advanced query GetUsersbyPerfil2: The multi-part identifier "YNVPVW020.DBO.OSUSR_R0Z_PERFILUSER.ID" could not be bound. The multi-part identifier "YNVPVW020.DBO.OSUSR_R0Z_PERFILUSER.PERFILID" could not be bound. The multi-part identifier "YNVPVW020.DBO.OSUSR_R0Z_PERFILUSER.USERID" could not be bound. The multi-part identifier "YNVPVW020.DBO.OSUSR_R0Z_PERFILUSER.ISITADDED" could not be bound.

What am I doing wrong?


Rank: #68
Solution

Hi lucas,


You're using alias but not on your select, that's why.

On your select, you also need to use alias, so on your SELECT instruction instead of  {PerfilUser}.* you need to have FirstUser.* or SecondUser.* (you will know better from which you want to get the details).


Hope it helps.


Regards,
João