Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I have two and i want to update both table simultaneously. These two tables are have common RegNo Field
My Query Is

SQL
update OpdPatient as O inner join Registration as R on O.RegNo=R.RegNo set O.Department=@Department,
                O.Doctor=@Doctor,O.ReffBy=@ReffBy,O.Diagnosis=@Diagnosis,O.Category=@Category,O.MLC=@MLC,O.PoliceStation=@PoliceStation,
                O.FIRno=@FIRno,O.Identification=@Identification,O.Injury=@Injury,O.Singnature=@Signature,O.MLC_Charge=@MLC_Charge,O.Willing=@Willing,
                O.Remark=@Remark,O.broughtby=@broughtby,O.contactno=@contactno,O.DoctorFee=@DoctorFee,O.AddFee=@AddFee,O.Reason=@Reason,O.Discount= @Discount
                O.AdmitDate=@AdmitDate where RegNo=@PID

but it show incorrect syntax near the keyword as
Posted

update B set B.column1 = '' from tblB B, tblA A where A.Id = B.idA and B.idA = Condition


here A.Id = B.Ida because B.Ida has foreign key reference.
 
Share this answer
 
Hi,
U have to update all the variable values to ur table based on JOIN right...
Check the following Code....
SQL
update O SET set O.Department=@Department,O.Doctor=@Doctor,O.ReffBy=@ReffBy,O.Diagnosis=@Diagnosis,O.Category=@Category,O.MLC=@MLC,O.PoliceStation=@PoliceStation,
                O.FIRno=@FIRno,O.Identification=@Identification,O.Injury=@Injury,O.Singnature=@Signature,O.MLC_Charge=@MLC_Charge,O.Willing=@Willing,
                O.Remark=@Remark,O.broughtby=@broughtby,O.contactno=@contactno,O.DoctorFee=@DoctorFee,O.AddFee=@AddFee,O.Reason=@Reason,O.Discount= @Discount
                O.AdmitDate=@AdmitDate
FROM OpdPatient as O 
inner join Registration as R on O.RegNo=R.RegNo 
where O.RegNo=@PID

Regards,
GVPrabu
 
Share this answer
 
Update TableName 
SET    Column1='', Column2='' 
FROM   Table1 Inner JOIN Table2 
ON     Table1.Col=Table2.Col
 
Share this answer
 
v2

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