更新SQL表中的上一个值 [英] Updating previous value in SQL table
问题描述
我想在SQL表中添加新记录时更新以前的记录。有什么建议吗?
目前,当我创建一个新记录时,新的id及其值被添加到表中。
Id = 1值= PAC< br />
Id = 2值= PAC< br />
Id = 3值= PAC。等等.......
但是我希望在Vb.net中创建新记录后,行为如下所示。如果创建了新记录,则将之前ID的值更新为NUll。
Id = 1 Value = Null< br />
Id = 2 Value = PAC
我不知道你正在使用什么框架
如果你在插入后获得最后一行ID,如
int id = doInsert( PAC);
你可以不去吗
int numRows = doUpdateNull(id);
您的更新声明类似于
< span class =code-keyword> update table set value = Null 其中 Id< %1;
(使用正确的SQL构建器并将%1替换为传入函数doUpdateNull的id ...)
Hi,
I am trying to update previous record when a add a new record in the SQL table. Any suggestions?
Currently, when I create a new record, the new id and its value is added to the table.
Id=1 Value = PAC<br /> Id=2 Value = PAC<br /> Id=3 Value = PAC.and so on.......
But I want the behavior to be as below after I create a new record in Vb.net. If new record is created then update the value of the previous ID to be NUll.
Id=1 Value = Null<br /> Id=2 Value = PAC
I dont know what framework or such you're using
if you get the last row Id after an insert, as in
int id = doInsert("PAC");
can you not then go
int numRows = doUpdateNull(id);
where your update statement is something like
update table set value = Null where Id < %1;
(using a proper SQL builder and replacing %1 with id as passed into the function doUpdateNull...)
这篇关于更新SQL表中的上一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!