Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi... I want to update the details of Trns_Enrollmentmaster from Trns_Enrollmentdetails.. I'm passing few details from front end and remaining details updating from detail table...

When I'm trying to execute this query..I'm getting this error

The multi-part identifier could not be bound.

for those parameters taking from detail table...Can any one give suggestion for this.

What I have tried:

ALTER proc [dbo].[SP_T_PrimaryUpdate]


(@UHIDNO varchar(30),
@Yearautoid int,
@Membername varchar(50),
@ISPrimaryChanged bit,
@PrimaryChangeby varchar(50),
@Primarychangedon datetime,
@PrmaryChangedReason varchar(50),
@PrimaryChangedmembername varchar(50),
@PrimarychangeIP varchar(50))

AS
  BEGIN
        
        UPDATE Trns_Enrollmentmaster  SET Membername=@Membername,ISPrimaryChanged=@ISPrimaryChanged,
               Primarychangedon=@Primarychangedon,PrimaryChangeby=@PrimaryChangeby,PrimaryChangedmembername=@PrimaryChangedmembername,
               PrmaryChangedReason=@PrmaryChangedReason,
               PrimarychangeIP=@PrimarychangeIP, Age =a.age, Photo=a.photo, Gender = a.Gender
               
               SELECT a.age,a.photo,a.Gender FROM dbo.Trns_Enrollmentdetails AS a INNER JOIN dbo.Trns_Enrollmentmaster  ON a.UHIDNO=@UHIDNO and a.Yearautoid=@Yearautoid  AND Trns_Enrollmentmaster.UHIDNO=@UHIDNO AND Trns_Enrollmentmaster.Yearautoid=@Yearautoid 
      END
Posted
Updated 18-Feb-20 0:50am
Comments
Richard Deeming 23-Feb-17 16:25pm    
When you get an error message, post the full error message. Don't paraphrase it; don't summarise it; don't simplify it. If you do, you risk removing the important information.

You should only ever remove sensitive information, like usernames, passwords, API keys, etc.

The full error message will look something like The multi-part identifier "..." could not be bound. The part within the quotes, which you have removed, tells you which identifier is causing the problem.

Google is your friend. This search turned up a lot of possible answersa for you:
The multi-part identifier could not be bound. - Google Search[^]

... including this gem: sql - What is a 'multi-part identifier' and why can't it be bound? - Stack Overflow[^]
 
Share this answer
 
There is a chance when using joins columns name may be same.. use alias name for the columns...It was worked in my case...
 
Share this answer
 
v2
Comments
CHill60 18-May-17 5:10am    
The situation you are describing would have resulted in the error "Ambiguous column name..." and NOT "The multi-part identifier ... could not be bound".
Your problem was the clause
PrimarychangeIP=@PrimarychangeIP, Age =a.age, Photo=a.photo, Gender = a.Gender
because you have used an alias a that is not defined anywhere in that UPDATE command.
If you want to do an update from a join then the (single) query should look like (untested)
UPDATE EM SET Membername=@Membername,ISPrimaryChanged=@ISPrimaryChanged,
       Primarychangedon=@Primarychangedon,PrimaryChangeby=@PrimaryChangeby,PrimaryChangedmembername=@PrimaryChangedmembername,
       PrmaryChangedReason=@PrmaryChangedReason,
       PrimarychangeIP=@PrimarychangeIP, Age =a.age, Photo=a.photo, Gender = a.Gender
FROM dbo.Trns_Enrollmentdetails AS a 
INNER JOIN dbo.Trns_Enrollmentmaster  AS EM ON a.UHIDNO=EM.UHIDNO AND a.Yearautoid=EM.Yearautoid
WHERE a.UHIDNO=@UHIDNO and a.Yearautoid=@Yearautoid
There is a clear example in my article Processing Loops in SQL Server[^] - look for "Updating Tables Using Joins"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900