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触发器,根据条件匹配另一个表中的字段的更多相关文章

  1. SQL查询一个表中类别字段中Max()最大值对应的记录

      SQL查询一个表中类别字段中Max()最大值对应的记录 SELECT A.id, A.name, A.version FROM   DOC A, (SELECT id, MAX(version)  ...

  2. 如何使用MySQL一个表中的字段更新另一个表中字段

    [本文出自:https://www.jb51.net/article/150323.htm] 这篇文章主要介绍了如何使用MySQL一个表中的字段更新另一个表中字段,需要的朋友可以参考下 1,修改1列 ...

  3. 获取一个表中的字段总数(mysql) Navicat如何导出Excel格式表结构 获取某个库中的一个表中的所有字段和数据类型

    如何获取一个表中的字段总数 1.function show columns from 表明: 结果 : 2.functiuon select count(*) from INFORMATION_SCH ...

  4. delete表1条件是另一个表中的数据,多表连接删除(转)

    DELETE删除多表数据,怎样才能同时删除多个关联表的数据呢?这里做了深入的解释: 1. delete from t1 where 条件 2.delete t1 from t1 where 条件 3. ...

  5. sql server 国内外 2个同步 ,加一个表.加入同步种

    国内 和国外sql server 订阅 ,数据同步. 因为表是刚开始就弄好的. 那么如果国内加一个表.国外没法同步过去 步骤:1.国外也建一个一抹一样的表 步骤:2.把国内的数据导入到国外 步骤:3. ...

  6. 一个表中的字段值用作另一个表的In查询条件

    Question表与Paper表 Paper表中字段QuestionIds存储的是Question表中字段Id的拼接后的值 如: 'f855eba1-b308-4bd7-a250-c071a0e1bd ...

  7. 一个sql实现查询并且插入到另一个表中

    两种不同方法,结果不同 方法一.查询的user表中3个元素,name为user表中的字段,1000,0,是往department中要赋的值(给id赋值) ,`name`,' 方法二(推荐使用方法二): ...

  8. Sql Server关于日期查询时,如果表中日期到具体某个时间

    1.如果查询日期参数为'2017/02/21',而数据库表中的字段为'2017/02/21 12:34:16.963',则需要格式化一下日期才能查询出来,如下 select * from table ...

  9. sql查询并把数据更新到另一个表中

    update OpenBills set peopleCount=(select rtNumber from Rooms where obId='ZD201005223') where obId='Z ...

随机推荐

  1. HTML5+规范:Webview(管理应用窗口界面)

    一.知识点 Webview模块管理应用窗口界面,实现多窗口的逻辑控制管理操作.通过plus.webview可获取应用界面管理对象. 1.方法 1.1.all: 获取所有Webview窗口 Array[ ...

  2. 用.netcore写一个简单redis驱动,调试windows版本的redis.平且给set和get命令添加参数.

    1. 下载windows版本的redis 2.开发环境vs2017  新建一个 .net core控制台. private static Socket socket = new Socket(Addr ...

  3. NetCore入门篇:(四)Net Core项目启动文件Startup

    一.Startup介绍 1.Startup文件是Net Core应用程的启动程序,实现全局配置. 2.Net Core默认情况下,静态文件及Session都未启动,需要在Startup文件配置启动,否 ...

  4. 3D Spherical Geometry Kernel( Geometry Kernels) CGAL 4.13 -User Manual

    Introduction The goal of the 3D spherical kernel is to offer to the user a large set of functionalit ...

  5. poj3026

    Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12952   Accepted: 4227 Descri ...

  6. 解决ie9以下浏览器对html5新增标签的不识别,并导致CSS不起作用的问题

    https://www.cnblogs.com/yangjie-space/p/4816279.html html5shiv.js和respond.min.js 做页面常用的东西,写这里用的时候省点去 ...

  7. 一种基于zookeeper的分布式队列的设计与实现

    package com.ysl.zkclient.queue; import com.ysl.zkclient.ZKClient; import com.ysl.zkclient.exception. ...

  8. iOS 模拟不同的字体大小

     真的是神器!! 参考 Creating Self-Sizing Table View Cells

  9. D10——C语言基础学PYTHON

    C语言基础学习PYTHON——基础学习D10 20180906内容纲要: 1.协程 (1)yield (2)greenlet (3)gevent (4)gevent实现单线程下socket多并发 2. ...

  10. OS之进程管理---孤儿进程和僵尸进程

    僵尸进程 当一个进程终止时,操作系统会释放其资源,不过它位于进程表中的条目还是在的,直到它的父进程调用wait():这是因为进程表中包含了进程的退出状态.当进程已经终止,但是其父进尚未调用wait() ...