我的dbgrid和一个数据表相关
表里面有学院,系,教研室,它们的teachingunitno,编号都是六位,依次是学院号,系号,教研室号,举个例子,当我在dbgrid中修改学院的编号时,他下面的系将自动更改,通过在sql的服务器端编写触发器可以实现吗?有没有其他办法可以实现?不知各位大侠有何高见,请指教,谢了。
表里面有学院,系,教研室,它们的teachingunitno,编号都是六位,依次是学院号,系号,教研室号,举个例子,当我在dbgrid中修改学院的编号时,他下面的系将自动更改,通过在sql的服务器端编写触发器可以实现吗?有没有其他办法可以实现?不知各位大侠有何高见,请指教,谢了。
解决方案 »
- d7导入EXCEL,导出TXT后小数点问题
- delphi 判定文本框输入值是否在0到10之间
- 开发VPN服务端代码,有难度哦!!!
- 如何调用保存在 TMemoryStream 中的DLL?
- 各位来看看,DELPHI 7所有数据库程序,在XP下报Operation not applicable错误!
- loginprompt 登陆框的问题??
- 再delphi怎样备份数据。和还原数据,举实例!!!
- 不知道为什么....
- 请问TINIFILES在DELPHI的什么位置??我的DELPHI中找不到,SOS!
- 如何让Query动态的一次执行多条SQL语句!
- 在INSTALLSHIELD中申明一个函数,返回STRING。为什么出错?
- clisentDataSet ApplayUpdate时出现错误!
我以前没有用过触发器,
我该怎么判断变化的是学院还是系
还有如何写具体的更改代码
下面的对吗?
if update(TeachingUnitNo)
begin
if(@numaffected=1)
begin
select @unitno from deleted
select @newUnitno from inserted
if substring(@unitno,1,4)=substring(@newunitno,1,4)
return
else
begin
if substring(@unitno,1,2)=substring(@newunitno,1,2)
begin
update ini_TeachingUnit
set TeachingUnitNo=substring(@newunitno,1,4)+substring(@unitno,5,2)
where teachingUnitno=substring(@unitno,1,4)+'##'
end
else
begin
update Ini_TeachingUnit
set TeachingUnitNo=substring(@newunitno,1,2)+substring(@unitno,3,4)
where teachingUnitNo=substring(@unitno,1,2)+'####'
end
给点帮助吧。
FOR UPDATE
AS
if not exists(select * from ast_stock
where chr_pactid=(select chr_pactid from inserted) and vchr_cnfactoryid=(select vchr_cnfactoryid from inserted)
and vchr_inproduct = (select vchr_inproduct from inserted)
and vchr_color=(select vchr_color from inserted) and vchr_size =(select vchr_size from inserted)
and chr_cargograde=(select chr_cargograde from inserted))
insert ast_stock(chr_PactID,vchr_cnfactoryid,vchr_InProduct,vchr_Color,vchr_Size,vchr_Unit,chr_CargoGrade,int_CtnNum,int_PcsNum)
select chr_PactID,vchr_cnfactoryid,vchr_InProduct,vchr_Color,vchr_Size,vchr_Unit,chr_CargoGrade,int_CtnNum,int_PcsNum from inserted
else
update ast_stock
set ast_stock.int_ctnnum=ast_stock.int_ctnnum+inserted.int_ctnnum,ast_stock.int_pcsnum=ast_stock.int_pcsnum+inserted.int_pcsnum
from inserted
where ast_stock.chr_pactid= inserted.chr_pactid and
ast_stock.vchr_cnfactoryid=inserted.vchr_cnfactoryid and ast_stock.vchr_inproduct=inserted.vchr_inproduct and
ast_stock.vchr_color=inserted.vchr_color and ast_stock.vchr_size=inserted.vchr_size and
ast_stock.chr_cargograde=inserted.chr_cargograde
看看,我要下班了:)