0

Hi,

I'm just want to ask if it's possible if I want to update multiple record with same condition at the same time.

For example, I have a table named userTable, it has two field, year and status fields.
On year field, it has value of years and on status field has default value New.

I'am using asp to perform this operation :

var status = "Expired";
var year = "2012";

var sql  = "UPDATE userTable ";
    sql += "SET ";
    sql += "status = '"+status+"'";
    sql += "WHERE ";
    sql += "year = " +year;

On year field, it has multiple record that has value 2012. So, what i'm trying to do is to update record on status field which the year is equal to 2012.

It can run smoothly if only one record has year value equal to 2012, but not if has multiple record with same value.

I'm already try to run this code but got error. So, anyone can help me solve this problem.
Thank You.

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by debasisdas
0

UPDATE alters all records to which the condition applies. It does not matter if it applies only to one, to several, to none or to all records.
For multiple conditions add them to the WHERE clause with the boolean operators AND, NOT and OR, like in

UPDATE userTable SET status = 'New' WHERE year = 2000 OR year = 2001;
0

It can run smoothly if only one record has year value equal to 2012, but not if has multiple record with same value.

I don't see why this code will not work.
By the way what is the error you are getting ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.