如果项目存在,如何应用更新,否则如何插入 [英] How to apply Update if an item exists and Insert otherwise
问题描述
如何创建从表顶部开始并将值与空值进行比较的过程- 如果找到匹配项,则在此位置插入一个元素.- 如果不是,则将元素插入新行
How to create a procedure that goes from the top of the table and compares the value to null - If a match is found, insert an element in this position. - If not, the element is inserted into a new row
我需要更正第二行,该行在最后 4 列中包含空值,而不管 Id 和 PropertyId 列中的值如何
I need to correct a second row which contains null values in 4 last columns regardless of values in the Id and PropertyId columns
这是我的数据库截图
以下是数据示例:
现在它可以工作了,这不适合我,而是应该像上一个屏幕截图一样使用空值更新行
Now it works so, which is not suitable to me, instead it should update the row with null values like on the last screenshot
但是下一个条目应该覆盖 Item、ItemId、InstanceId 和 Instance 的 NULL 值
But the next entry should overwrite the value of NULL for Item, ItemId, InstanceId and Instance
推荐答案
编写如下存储过程:
create procedure INSERT_OR_UPDATE as
begin
if exists ( select * from Numerations where <your condition> )
begin
update Numerations set < ... > where < ... >
end
else
begin
insert into Numerations values <...>
end
end
您必须检查语法,因为我现在无法测试我的代码.
You have to check the syntax because I cannot test my code right now.
这篇关于如果项目存在,如何应用更新,否则如何插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!