when not exists 用法
USE [ChangHong_612]
GO
/****** Object: StoredProcedure [dbo].[st_MES_UpdateInspectResult] Script Date: 10/09/2015 16:15:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: luoxf
-- Create date: 20141023
-- Description: 审核检测
-- =============================================
ALTER PROCEDURE [dbo].[st_MES_UpdateInspectResult] (
@BillNo nvarchar(50),
@CheckMan nvarchar(20),
@Result nvarchar(10)
)
AS
BEGIN
--select abnormalno,* from mes_Inspect where AbnormalNO is not null and checkman is not null order by CheckTime desc
if exists(select * from mes_Inspect where billno=@billno and checkman is not null)
return
if (@Result='NG')
begin
declare @InitValue_IP varchar(50),@Month varchar(10),@InitValue_F varchar(50),@InitValue_O varchar(50)
set @Month=month(getdate())
if (len(@Month)=1)
set @Month ='0'+@Month
select @InitValue_IP = isnull(max(substring(abnormalno,len(abnormalno)-2,len(abnormalno))),0)from MES_Inspect
where abnormalno<> '' and substring(abnormalno,1,4)=convert(varchar(4),getdate(),112) and abnormalno like '%IPQC-ZC-%'
select @InitValue_F = isnull(max(substring(abnormalno,len(abnormalno)-2,len(abnormalno))),0)from MES_Inspect
where abnormalno<> '' and substring(abnormalno,1,4)=convert(varchar(4),getdate(),112) and abnormalno like '%FQC-ZC-%'
select @InitValue_O = isnull(max(substring(abnormalno,len(abnormalno)-2,len(abnormalno))),0)from MES_Inspect
where abnormalno<> '' and substring(abnormalno,1,4)=convert(varchar(4),getdate(),112) and abnormalno like '%OQC-ZC-%'
select @InitValue_IP = convert(int,@InitValue_IP)+1
select @InitValue_F = convert(int,@InitValue_F)+1
select @InitValue_O = convert(int,@InitValue_O)+1
update mes_Inspect
set abnormalno=convert(varchar(4),getdate(),112)+'MS-SL2-'+
case
when checktype in(1,2,3,4) then 'IPQC'+'-ZC-'+@Month+'-'+replace(str(right(@InitValue_IP,3), 3), space(1), '0')
when checktype=5 then
case when CONVERT(nvarchar,DateName(DAY,GETDATE()))='1'
then
case
when not exists(select * from mes_Inspect where abnormalno like '%'+'FQC'+'-ZC-'+@Month+'-'+'%')
then 'FQC'+'-ZC-'+@Month+'-'+'001'
else 'FQC'+'-ZC-'+@Month+'-'+replace(str(right(@InitValue_F,3), 3), space(1), '0')
end
else
'FQC'+'-ZC-'+@Month+'-'+replace(str(right(@InitValue_F,3), 3), space(1), '0')
end
when checktype=6 then 'OQC'+'-ZC-'+@Month+'-'+replace(str(right(@InitValue_O,3), 3), space(1), '0')
end
,
checkResult=@result,
checkman=@checkMan,
checktime=getdate()
where billno=@billno
end
else
begin
update mes_Inspect set checkResult=@result,checkman=@checkMan,checktime=getdate() where billno=@billno and checkman is null
update mes_inspectsingle set Itemvalue=case when itemvalue='NG' then 'OK' else Itemvalue end where billno=@BillNo
update MES_InspectGauge set CheckResult=case when CheckResult='NG' then 'OK' else CheckResult end where billno=@BillNo
end
end
--select abnormalno , * from mes_Inspect where abnormalno like '%'+'IPQC'+'-ZC-'+'07'+'-'+'%'
when not exists 用法的更多相关文章
- oracle中的exists 和not exists 用法详解
有两个简单例子,以说明 “exists”和“in”的效率问题 1) select * from T1 where exists(select 1 from T2 where T1.a=T2.a) ; ...
- oracle中的exists 和not exists 用法 in与exists语句的效率问题
博文来源(oracle中的exists 和not exists 用法):http://chenshuai365-163-com.iteye.com/blog/1003247 博文来源( in与exi ...
- oracle中的exists 和not exists 用法详解(转)
有两个简单例子,以说明 “exists”和“in”的效率问题 1) select * from T1 where exists(select 1 from T2 where T1.a=T2.a) ; ...
- Oracle exists 和not exists 用法详解
有两个简单例子,以说明 “exists”和“in”的效率问题 1) select * from T1 where exists(select 1 from T2 where T1.a=T2.a) ; ...
- sql server if exists用法
if exists用法 if exists 判断表中的内容是否存在 IF EXISTS(SELECT FROM proprice_sheet WHERE vndcode = @vndc ...
- sql语句exists 用法
参考:SQL语句exists用法,Sql语句中IN和exists的区别及应用 现在有三张表 学生表S: sno ,sname 课程表C:cno ,cname 学生选课表SC: sno ,cno 查询选 ...
- MyBatis框架中的条件查询!关键字exists用法的详细解析
exists用法 exists: 如果括号内子查询语句返回结果不为空,说明where条件成立,就会执行主SQL语句 如果括号内子查询语句返回结果为空,说明where条件不成立,就不会执行主SQL语句 ...
- Mysql之IN 和 Exists 用法
1.基本用法 IN:后面的子查询 是返回结果集的,换句话说执行次序和Exists()不一样.子查询先产生结果集,然后主查询再去结果集里去找符合要求的字段列表去.符合要求的输出,反之则不输出. Exis ...
- mssql sqlserver if exists 用法大汇总
摘要: 下文讲述sqlserver中,更新脚本中常用if exists关键字的用法说明,如下所示: 实验环境:sql server 2008 R2 一.检测数据库是否存在于当前数据库引擎下 if ex ...
- sql 中 exists用法
SQL中EXISTS的用法 比如在Northwind数据库中有一个查询为SELECT c.CustomerId,CompanyName FROM Customers cWHERE EXISTS(S ...
随机推荐
- Qt之进程间通信(IPC)
简述 进程间通信,就是在不同进程之间传播或交换信息.那么不同进程之间存在着什么双方都可以访问的介质呢?进程的用户空间是互相独立的,一般而言是不能互相访问的,唯一的例外是共享内存区.但是,系统空间却是& ...
- js对联广告代码,兼容性高
var browser = { ie6: function () { return ((window.XMLHttpRequest == undefined) && (ActiveXO ...
- Java 7 语法新特性
一.二进制数字表达方式 原本整数(以60为例)能够用十进制(60).八进制(074).十六进制(0x3c)表示,唯独不能用二进制表示(111100),Java 7 弥补了这点. public clas ...
- 一个P2P点播直播开源项目:P2PCenter
最近跟着公司的项目走,我也研究了不少东西,尤其是在P2P方面,广泛涉猎各种开源项目,尤其是国外的开源项目,意外的发现了一个国内的项目,做的还不错,推荐一下.---------------------使 ...
- fzu 1675 The Seventy-seven Problem
给你长度为 10^5~10^6长度,由数字组成的串 其中有4位不见了 补全该串 使得在该串能整除 77的同时 尽可能大// 先计算出每个 n*10^m 模 77 的循环节 n=0,1,2..,9// ...
- 【转】apue《UNIX环境高级编程第三版》第一章答案详解
原文网址:http://blog.csdn.net/hubbybob1/article/details/40859835 大家好,从这周开始学习apue<UNIX环境高级编程第三版>,在此 ...
- 屏蔽页面js报的错误
有时候,某些js的错误,确实没有什么大影响,但是这个又实在没办法. 一般,下下策采取 <script language="javascript"> function k ...
- 通过js检测到iframe,使父窗口重定向到index -----------???----------------------
通过js检测到iframe,使父窗口重定向到index -----------???---------------------- 如果本身已将在iframe中,那么重定向的页面应该直接添加到父级ifr ...
- Asp.Net Core(.net内核)
Asp.Net Core(.net内核) //----------------Day1----------------一章 Web基本原理 1节课程说明 web窗体--设计界面--加法使用Chr ...
- POJ 2456 Aggressive cows
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11192 Accepted: 5492 ...