• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

sql update statement with inner join

Hello,

I am using vb.net 2005 and an SQL Server database

i have 2 tables, I want to update a field in the first table if 2 fields in the second table are as specified.

I have tried the following code but it returns an error
"Incorrect syntax near the keyword INNER"

Any help would be greatly appreciated,

Thanks.
Dim comm As New SqlCommand("UPDATE Appointments INNER JOIN " & _
                                   "PatientDet ON Appointments.patientNIN = PatientDet.NIN " & _
                                   "SET Appointments.checkedIn = True " & _
                                   "WHERE PatientDet.NIN = '" & txtNin.Text.ToString.Trim & "'" & _
                                   "AND PatientDet.lastName = '" & txtSurname.Text.ToString.Trim & "'", dbHandling.getDbConn)
 
        Try
            comm.Connection.Open()
            comm.ExecuteNonQuery()
            comm.Connection.Close()
 
        Catch ex As Exception
            MessageBox.Show(ex.Message)
 
        End Try

Open in new window

0
pythonV
Asked:
pythonV
1 Solution
 
reb73Commented:
Try changing Line 1 as follows -
Dim comm As New SqlCommand("UPDATE Appointments SET Appointments.checkedIn = True " & _
                                   "FROM Appointments INNER JOIN " & _
                                   "PatientDet ON Appointments.patientNIN = PatientDet.NIN " & _
                                   "WHERE PatientDet.NIN = '" & txtNin.Text.ToString.Trim & "'" & _
                                   "AND PatientDet.lastName = '" & txtSurname.Text.ToString.Trim & "'", dbHandling.getDbConn)

Open in new window

0
 
pythonVAuthor Commented:
That did the trick!

Thanks alot,

Regards,

pythonV
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now