Domanda

I'm working on a website where the LoginID and Password for the students will be provided by the University. I'm designing a webpage with fields FirstName, MiddleName, LastName, DOB, Email, MobileNo, PhoneNo, PreviousName, FathersName, InstituteName, Gender, and Password.

The values will go to three different tables. I'm using LoginID for WHERE statement to update two tables but the third table doesn't has LoginID column. The third table has FirstName, MiddleName, LastName, PreviousName, FathersName and UserDetailID columns. UserDetailID column is also present in the other two tables.

How do I update the third table?

All that I'm doing is that I'm retrieving LoginID from the Session and using it in the WHERE statement which I can't do for the third table as LoginID column is not present in the third table. I don't have the permission to add any new columns in the table.

I've tried;

update UserDetail
 set FirstName = @FirstName, 
       MiddleName = @MiddleName, 
       LastName = @LastName, 
       Mobile = @MobileNo, 
       Phone = @PhoneNo, 
       PeviousName = @PreviousName, 
       FathersName = @FathersName, 
       DateOfBirth = @DOB, 
       Gender = @Gender 
  where LoginID = @LoginID"
È stato utile?

Soluzione

you have to join tables based on common columns, it is basics of sql.

Update can also have join like:

update UD 
   set FirstName = @FirstName, 
       MiddleName = @MiddleName, 
       LastName = @LastName, 
       Mobile = @MobileNo, 
       Phone = @PhoneNo, 
       PeviousName = @PreviousName, 
       FathersName = @FathersName, 
       DateOfBirth = @DOB, 
       Gender = @Gender 
FROM UserDetail UD
   INNER JOIN LOGIN L--OR whatever your table name is 
     ON L.UserDetailID =UD.UserDetail 
        WHERE UD.LoginID = @LoginID

refer Join Fundamentals for learning join

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top