我有一个asp.net Web应用程序,用户可以在其中更新数据库中的表。
我在SQL Server 2008中有一个如下所示的表:
lom_number(fk) problem primarykey
1 AA 1
1 AA1 2
1 AA3 3
23 B 4
22 C 5
用户有一个前端,可以根据foreignkey
用户可以更新这样的数据:
到目前为止,我有这个:
create procedure Merge_lom_problem
as
merge [dbo].lom_problem as target
using temp.lom_problem as SOURCE
on (target.lom_number = SOURCE.lom_number)
when matched and (target.problem <> SOURCE.problem)
insert (lom_number,problem) values (SOURCE.lom_number,SOURCE.problem)
when matched and
但是我遇到了#2和#3的问题。
你能帮忙编码吗?
答案 0 :(得分:0)
第一个问题你说什么都不对?
试试这个
create procedure Merge_lom_problem
as
merge [dbo].lom_problem as target
using temp.lom_problem as SOURCE
on (target.lom_number = SOURCE.lom_number)
--when matched and target.problem = SOURCE.problem then
when not matched by source then
DELETE
when not matched by target then
insert (lom_number,problem) values (SOURCE.lom_number,SOURCE.problem)
但我不确定它会起作用,因为我还没有测试