我的dbgrid和一个数据表相关
表里面有学院,系,教研室,它们的teachingunitno,编号都是六位,依次是学院号,系号,教研室号,举个例子,当我在dbgrid中修改学院的编号时,他下面的系将自动更改,通过在sql的服务器端编写触发器可以实现吗?有没有其他办法可以实现?不知各位大侠有何高见,请指教,谢了。
表里面有学院,系,教研室,它们的teachingunitno,编号都是六位,依次是学院号,系号,教研室号,举个例子,当我在dbgrid中修改学院的编号时,他下面的系将自动更改,通过在sql的服务器端编写触发器可以实现吗?有没有其他办法可以实现?不知各位大侠有何高见,请指教,谢了。
解决方案 »
- 求极通EWES 20090217安装程序的下载地址
- 很奇怪的問題,不知道大家有沒碰到.請高手進!
- 有苏州的同学没?打听个学校?
- 怎样判断变量的类型 ?stringgrid1.cells[i,j]启出来的值是什么类型的?
- 请教一个关于C++Builder与Delphi之间转换的问题,在线等待中...
- delphi如何连接数据库的 ?
- 谁知道压缩软件是怎么做的?
- 如何自动运行某一程序?
- 关于blob字段问题,急!!!,在线等待,解决就给分!!!,救命啊!!
- batchmove的使用
- 在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
看看,我要下班了:)