Sql-Server触发器,根据条件匹配另一个表中的字段
USE [CDM]
GO
/****** Object: Trigger [dbo].[UpdateAkisFlight] Script Date: 2018/6/14 16:43:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO ALTER TRIGGER [dbo].[UpdateAkisFlight]
ON [dbo].[FlightWarnTime]
FOR INSERT,DELETE
AS
BEGIN
if(exists(select from inserted) and not exists(select from deleted))
begin
declare @TwoCode nvarchar(),@FlightNum nvarchar(),@ThreeCode nvarchar(),@Etd datetime,@FlightId int,@Calsign nvarchar(),@ID int
select @TwoCode=TwoCode,@FlightNum=FlightNumber,@Etd = Etd,@ID = Id from inserted
select @ThreeCode=Code3 from Company with(nolock) where Code2=@TwoCode
if @ThreeCode is not null
begin
set @Calsign=@ThreeCode+@FlightNum
if @FlightNum is not null
begin
update [dbo].[FlightWarnTime] set Calsign=@Calsign where Id=@ID
end
if @Etd is not null
begin
select @FlightId=FlightId from [AKIS].[dbo].[ValidFlight] with(nolock) where Calsign=@Calsign and ABS(DATEDIFF(MINUTE,Etd,@Etd)) <= and DepAddrName='ZHCC'
end
if @FlightId is not null
begin
update [dbo].[FlightWarnTime] set AkisFlightId=@FlightId where Id=@ID
end
end
end
END
Sql-Server触发器,根据条件匹配另一个表中的字段的更多相关文章
- SQL查询一个表中类别字段中Max()最大值对应的记录
SQL查询一个表中类别字段中Max()最大值对应的记录 SELECT A.id, A.name, A.version FROM DOC A, (SELECT id, MAX(version) ...
- 如何使用MySQL一个表中的字段更新另一个表中字段
[本文出自:https://www.jb51.net/article/150323.htm] 这篇文章主要介绍了如何使用MySQL一个表中的字段更新另一个表中字段,需要的朋友可以参考下 1,修改1列 ...
- 获取一个表中的字段总数(mysql) Navicat如何导出Excel格式表结构 获取某个库中的一个表中的所有字段和数据类型
如何获取一个表中的字段总数 1.function show columns from 表明: 结果 : 2.functiuon select count(*) from INFORMATION_SCH ...
- delete表1条件是另一个表中的数据,多表连接删除(转)
DELETE删除多表数据,怎样才能同时删除多个关联表的数据呢?这里做了深入的解释: 1. delete from t1 where 条件 2.delete t1 from t1 where 条件 3. ...
- sql server 国内外 2个同步 ,加一个表.加入同步种
国内 和国外sql server 订阅 ,数据同步. 因为表是刚开始就弄好的. 那么如果国内加一个表.国外没法同步过去 步骤:1.国外也建一个一抹一样的表 步骤:2.把国内的数据导入到国外 步骤:3. ...
- 一个表中的字段值用作另一个表的In查询条件
Question表与Paper表 Paper表中字段QuestionIds存储的是Question表中字段Id的拼接后的值 如: 'f855eba1-b308-4bd7-a250-c071a0e1bd ...
- 一个sql实现查询并且插入到另一个表中
两种不同方法,结果不同 方法一.查询的user表中3个元素,name为user表中的字段,1000,0,是往department中要赋的值(给id赋值) ,`name`,' 方法二(推荐使用方法二): ...
- Sql Server关于日期查询时,如果表中日期到具体某个时间
1.如果查询日期参数为'2017/02/21',而数据库表中的字段为'2017/02/21 12:34:16.963',则需要格式化一下日期才能查询出来,如下 select * from table ...
- sql查询并把数据更新到另一个表中
update OpenBills set peopleCount=(select rtNumber from Rooms where obId='ZD201005223') where obId='Z ...
随机推荐
- RabbitMQ基础入门篇
下载安装 Erlang RabbitMQ 启动RabbitMQ管理平台插件 DOS下进入到安装目录\sbin,执行以下命令 rabbitmq-plugins enable rabbitmq_manag ...
- Sql Server字符串拆分(Split)方法汇总
详细链接:https://shop499704308.taobao.com/?spm=a1z38n.10677092.card.11.594c1debsAGeak--方法0:动态SQL法 declar ...
- 简单版nginx lua 完成流量上报于中间件
本文链接:https://www.cnblogs.com/zhenghongxin/p/9131226.html 公司某些业务下,需要将请求的流量上报于中间件(kafka,rabbitMq等),让st ...
- Python replace方法的使用
在Python str 中, 有一个很方便的查找替换的函数 replace() my_str = "lowmanmana" new_str = my_str.replace(&qu ...
- rocketmq学习
官网地址 安装name server和broker git clone https://github.com/apache/incubator-rocketmq.git cd incubator-ro ...
- nginx 开启GZIP、域名指向index.html
nginx 虽然默认开启了gzip压缩,但是有关压缩文件.压缩效率没有开启,在建设我的(个人博客)[www.fayinme.cn]中,直观的感受到gzip带来的访问速度提升的快感. 如何开启GZIP ...
- Python小白学习之路(十六)—【内置函数一】
将68个内置函数按照其功能分为了10类,分别是: 数学运算(7个) abs() divmod() max() min() pow() round() sum() 类型转换(24个) bo ...
- 布隆过滤器redis缓存
Bloom Filter布隆过滤器算法背景如果想判断一个元素是不是在一个集合里,一般想到的是将集合中所有元素保存起来,然后通过比较确定.链表.树.散列表(又叫哈希表,Hash table)等等数据结构 ...
- java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification
ListView UI重绘时触发layoutChildren, 此时会校验listView的mItemCount与其Adapter.getCount是否相同,不同报错. ListView.layout ...
- ASP.NET 下使用特定身份完成windows服务的功能操作
今天部署项目的发现一个问题: 在本地Win7系统下利用Web页面完成Windows服务的功能操作(启动.停止.安装.卸载)都是正常的,而部署到Server2008系统下,再使用Web页面完成windo ...