顶楼上的
使用触发器来实现
对B表进行Insert和Update动作时,修改A表记录.
使用触发器来实现
对B表进行Insert和Update动作时,修改A表记录.
解决方案 »
- 请教游标的写法和用途?高手指点
- 为什么我用select和set方法都不能正确得到值呢?
- 菜鸟关于convert()的问题,请高手指教,急用!
- 存储过程更新问题?
- 求SQL语句!
- 请教一个触发器的问题
- 关于一个Sql语句的问题,怎么也不会写,需要大家帮忙解决一下
- 在线结贴,下面这个名怎样改?
- 哪里可以下载SQLServer2000EnterpriseEdition。我的是StandardEdition很多功能不支持。
- SQL SERVER 触发器中的INSERTED、DELETED,因问题简单,只能给10分
- 请问2台 sql2005之间同步数据怎么做?
- sqlserver2005 复制&订阅问题请高手,在线等!
drop table A
if exists(select * from sysobjects where name = 'B' and xtype = 'U')
drop table Bcreate table A(
id nvarchar(2),
店名 nvarchar(4),
日期 datetime,
応収金額 money,
実収金額 money
)
insert into A values('01','001','2004-12-26 10:54:37.000',10,10)
insert into A values('02','001','2004-12-26 11:54:37.000',11,10)
insert into A values('03','002','2004-12-26 12:54:37.000',12,12)create table B(
id nvarchar(2),
商品编码 nvarchar(4),
销售数量 int,
销售价 money,
实收金额 money
)
insert into B values('01','1001',1,10,10)
insert into B values('02','1002',1,5.5,5.5)
insert into B values('02','1003',1,5.5,5.5)
insert into B values('03','1004',1,12,12)if exists(select * from sysobjects where name = 'dd' and xtype = 'tr')
drop trigger dd
go
create trigger dd on B for delete
as
declare @id nvarchar(2),@money1 money,@money2 money
select @id = id from deleted
select @money1 = 销售价 from deleted
select @money2 = 实收金额 from deleted print @id
print @money1
print @money2 update A
set 応収金額 = 応収金額 - @money1,実収金額 = 実収金額 - @money2
where A.id = @id
go
--test date
select * from A
delete from B where 商品编码 = '1003'
select * from A
商品编码 商品名 规格 供应商
10001 式 X 001
10002 小 M 006
10003 大 I 001
10004 中 W 002把供应商编码为:001的销售记录全部删除
自己动手,丰衣足食啊,别太懒了
FROM t_sale_d Left Outer Join t_sale_h ON t_sale_d.saleno=t_sale_h.saleno
Left Outer Join t_goods on t_sale_d.itemno=t_goods.itemno
where t_goods.vendorno='20441'and t_sale_h.enddate> dateadd(day,-2,getdate()) and depot='0730002'