views:

53

answers:

2

My table name is table_1, fields are:

  • name
  • dept
  • location
  • status

Status is already 1, but I want to update the status into 2 based on a certain condition else not update. My code is

UPDATE Table_1
   SET model = @model, 
       make = @make, 
       [Asset Serial No / Service Tag] = @Asset, 
       [IT Asset Tag] = @AssetTag, 
       status = 2
 WHERE (Request_No = @PassNo)

I have designed a page in asp.net. There is a button reject. If I click that reject button, then the table can't update.when i click reject button it doesnt update wat code i can write a code in a storeprocedure for not updating

+2  A: 

That would be along the lines of:

update table_1 set status = 2 where <condition>;

Since you haven't specified what the condition is, a generic answer is all I can give.

Some examples would be:

update table_1 set status = 2 where name = 'Bob Smith';
update table_1 set status = 2 where dept in (22, 66);
update table_1 set status = 2 where location = 'San Francisco' and status = 1;

Update 1: Now that you've changed the entire question from a simple SQL one to one involving not executing an update if the user presses a REJECT button in ASP.Net :-), surely it's just a matter of not executing the SQL UPDATE statement in thebtnReject_Click (or whatever your REJECT control is called) method.

In other words, only run the SQL UPDATE in the btnOkay_Click method.

Update 2: If you're looking for an SQL query to execute that doesn't change the table, you can use the following:

update table_1 set status = status where request_no = @PassNo

although why you'd need this is beyond me. Why can't you just not execute an SQL statement in the situation where the user presses the REJECT button?

paxdiablo
A: 

Just a tip. If you have trouble with the where condition or you are not sure of the results it will cause, you can run a select command and work with it until you get the exact recordset you want to update:

SELECT * FROM table_1 where <<condition>>

Then copy the condition and paste it in your update command. It will ensure you will update only the records you wants to. It is valid for anothers commands like delete.

Regards.

j.a.estevan