799
Views
2
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?


2018-10-29 08-31-03
João Marques
 
MVP
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


UserImage.jpg
Rahul Maniyil

Hi. I have a similar issue occurring. I have 2 entities and would wish to create a dropdown list with the values from a resultant SQL query (records of one entity not in the other):

Could you please help. Thank you.

I tried both the queries below and keep getting same errors:

1)

SELECT {ProductMaster}.[SAPMaterialNumber], {PRODUCT_MAST}.[SAP_PR_DESC] 
from {PRODUCT_MAST} where {ProductMaster}.[SAPMaterialNumber] 
NOT IN
(select {Material_Table}.[SAP_MATERIAL_NUMBER] from {Material_Table});


2)

SELECT {ProductMaster}.[SAPMaterialNumber], {PRODUCT_MAST}.[SAP_PR_DESC] 
from {PRODUCT_MAST} where 
NOT EXISTS
(select {Material_Table}.[SAP_MATERIAL_NUMBER],{Material_Table}.[ITEM_DESCRIPTION]
 from {Material_Table}
 where {ProductMaster}.[SAPMaterialNumber] =  {Material_Table}.[SAP_MATERIAL_NUMBER]
 );


Error:

Database returned the following error: Error in advanced query SQL1: The multi-part identifier "IRU7WD034.dbo.OSUSR_4TC_PRODUCTMASTER.SAPMATERIALNUMBER" could not be bound. The multi-part identifier "IRU7WD034.dbo.OSUSR_4TC_PRODUCTMASTER.SAPMATERIALNUMBER" could not be bound.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.