Reputation: 57
I am writing a c++ application that connect to a Microsoft Access database through ODBC connection. When I update a database with a single primary key, I use the following SQL command:
UPDATE [MY_TABLE] SET [Type] = ?, [Value] = ?, [Rating] = ? WHERE [Part Number] = ?
I now have a need to update a record in a database with two primary keys where the primary keys are Part Number and Revision. I tried this command
UPDATE [MY_TABLE] SET [Type] = ?, [Value] = ?, [Rating] = ?, [Revision] = ? WHERE [Part Number] = ?
but it give me error if there's duplicate in the Part Number field. I also tried
UPDATE [MY_TABLE] SET [Type] = ?, [Value] = ?, [Rating] = ? WHERE [Part Number] = ?, [Revision] = ?
but it is not a correct format. How do I setup my command to update a database record with two primary keys?
Upvotes: 1
Views: 77
Reputation: 37472
Use AND
to instead of ,
in the WHERE
clause. It's not a list you use there, it's a Boolean expression.
UPDATE [MY_TABLE] SET [Type] = ?, [Value] = ?, [Rating] = ? WHERE [Part Number] = ? AND [Revision] = ?
Upvotes: 1