求教!!关于触发器

linbee 2003-08-30 10:25:01
各位帮帮忙想一下什么完成?
在材料入库表里面新增一条记录时判断动太库存表里否有与相同的记录[入库表的kfbm、xsd与动太库存表相同的记录]?如果有则修改DJ、SC字段相加否则新增一条!请问什么表达????
...全文
86 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
leimin 2003-08-31
  • 打赏
  • 举报
回复
....
if exists(select * from 动太库存表 wherer kfbm=@kfbm and xsd=@xsd)

update 入库表 set DJ= ...SC=... where wherer kfbm=@kfbm and xsd=@xsd
else

insert into 入库表 values(....)
friendliu 2003-08-31
  • 打赏
  • 举报
回复
if not exists(select 1 from 入库表 A,inserter b wherer a.kfbm=b.kfbm and a.xsd=b.xsd)
begin
insert into 入库表 select * from inserted
end
happydreamer 2003-08-31
  • 打赏
  • 举报
回复
create trigger tr on 材料入库表
instead of insert
as


if exists(select * from 动太库存表 a join inserted b on a.kfbm=b.kfbm and a.xsd=b.xsd)

begin
update 入库表 set DJ= ...SC=... where wherer kfbm=@kfbm and xsd=@xsd

else

insert into 入库表 select * from inserted
michealin 2003-08-30
  • 打赏
  • 举报
回复
直接在你

if exsits select ....... update ....

else

insert .....
yun198183 2003-08-30
  • 打赏
  • 举报
回复
学习

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧