Reputation: 19
I have certain code which throws this error and I have declared it in the functionality itself
IF @Functionality='UserDetails'
BEGIN
SELECT TOP 10 ROW_NUMBER() OVER(ORDER BY USR.USERBADGENO ASC) AS SNO,
USR.USERBADGENO,
USR.FIRSTNAME + ' ' + USR.LASTNAME AS USERNAME,
ISNULL(CONVERT(NVARCHAR(100),LST.LASTLOGIN), 'NO LOGS FOUND') AS LASTACCESSED,
APP.NAME AS APPNAME,
URD.USERROLECODE
FROM USERMASTER USR
INNER JOIN USERROLEDETAILS URD
ON URD.USERROLECODE = USR.USERROLE
INNER JOIN APPLICATIONS1 APP
ON APP.APPID = URD.APPID
LEFT JOIN LASTLOGINDETAILS LST
ON LST.USERID = USR.USERBADGENO
AND LST.APPID = APP.APPID
WHERE APP.APPID = @APPID
AND URD.USERROLECODE = @USERROLE
ORDER BY LST.LASTLOGIN DESC
END
I expect the output to display the records of last three months in the application in grid view
Complete error message:
Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "LST.LASTLOGIN" could not be bound. Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "APP.NAME" could not be bound. Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "URD.USERROLECODE" could not be bound.
Upvotes: 1
Views: 18607
Reputation: 8043
The
Error The multi-part identifier xxxxxx could not be bound
is thrown when the column which you have given in the query does not exist. When the compiler tries to compile the query, it will search for that column and since the Column does not exists, the query won't be compiled. So Please make sure that you have spelled the column names correctly. It may also occur if you have given the wrong alias name,
eg:
I have a Column UserName in User Table and Have EmployeeName in Employee table. So this query will work
SELECT UserName FROM User
SELECT EmployeeName FROM Employee
But instead, If I try the below it will fail
SELECT UserName FROM Employee
SELECT EmployeeName FROM User
So Please make sure that the names are spelled correctly
Upvotes: 3