开发者

SQL code for update

开发者 https://www.devze.com 2022-12-10 08:58 出处:网络
My table name is table_1, columns 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

My table name is table_1, columns 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 (Reque开发者_运维知识库st_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 the reject button, it doesn't update what code can I write in a stored procedure for not updating?


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消