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 ...
随机推荐
- memcache的最佳实践方案。
基本问题 1.memcached的基本设置 1)启动Memcache的服务器端 # /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 ...
- group by的使用
1.概述 2.原始表 3.简单Group By 4.Group By 和 Order By 5.Group By中Select指定的字段限制 6.Group By All 7.Group By与聚合函 ...
- Mac终端编译运行C++
1.在编辑器中写好C++代码 2.打开终端打开文件对应的地址 3.用g++命令来编译.cpp文件 4.用./文件名来运行 观察文件的目录可发现 g++ 源文件名 编译源文件,产生a.out ./文件名 ...
- android桌面小火箭升空动画
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceS ...
- 【LeetCode 229】Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...
- XAMPP:访问phpmyadmin出错的解决方案
来源:http://www.ido321.com/1246.html XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的建 XAMPP 软件站集成软件包,轻巧,用起来很方便.它提 ...
- jQuery/CSS3大屏下拉菜单 自定义子菜单内容
这是一款样式很酷的jQuery/CSS3下拉菜单,首先这款CSS3菜单是宽屏的,主要是下拉菜单非常大气,更重要的是,下拉菜单的内容可以自己定义,也就是说,下拉菜单中可以定义菜单.图片等HTML元素,是 ...
- VS20xx下项目开发目录管理方法
在VS20XX之后项目管理使用解决方案(solution)管理一个大的开发工程中多个项目(Project). 以下目录配置与工程名称无关,适用于一般的工程组织过程. 对于一般的生成可执行程序的工程,使 ...
- PhoneGap,Cordova[3.5.0-0.2.6]:生成Android项目时出现错误(An error occurred while listing Android targets)
我在升级到Cordova最新版本(3.5.0-0.2.6)后,在生成Android项目(cordova platform add android)时出现错误: Error: An error occu ...
- 最简单例子图解JVM内存分配和回收
一.简介 JVM采用分代垃圾回收.在JVM的内存空间中把堆空间分为年老代和年轻代.将大量(据说是90%以上)创建了没多久就会消亡的对象存储在年轻代,而年老代中存放生命周期长久的实例对象.年轻代中又被分 ...