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 ...
随机推荐
- bzoj1875: [SDOI2009]HH去散步
终于A了...早上按自己以前的写法一直WA.下午换了一种写法就A了qwq #include<cstdio> #include<cstring> #include<iost ...
- VS2005中乱码问题
VS2005打开某些文件(如.inc, js)的时候出现乱码: 解决方法: 工具 --> 选项 --> 文本编辑器 --> 将“自动检测不带签名的 UTF-8编码”选中保存即可. V ...
- 如何解决:ERROR: the user data image is used by another emulator. aborting 的问题
问题概述: 在启动Android模拟器时出现以下错误,导致启动失败. ERROR: the user data image is used by another emulator. aborting. ...
- JetBrains优秀工具推荐
1.JAVA开发工具 IDEA IDEA 全称 IntelliJ IDEA,是Java语言开发的集成环境,IntelliJ在业界被公认为最好的Java开发工具之一,尤其在智能代码助手.代码自动提示.重 ...
- Linux 7 中Yum 配置 说明
在之前的Blog中写了Linux Yum 的配置方法,参考: Linux 平台下 YUM 源配置 手册 http://www.cndba.cn/account/article/details/154 ...
- Solr部署如何启动
我刚接触solr,我要怎么启动,这是群里的朋友问得比较多的问题, solr最新版本下载地址: http://www.apache.org/dyn/closer.cgi/lucene/solr/ 1.准 ...
- JS实现连接方式的菜单
<html> <head><meta http-equiv="Content-Language" content="zh-cn"& ...
- 【转】SDP file
SDP file Introduction The Session Description Protocol (SDP) is a format for describing the initiali ...
- .net 接口返回json格式示例
1.新建 InterfaceTestPro1 项目: FILE - New - Project... - Web - ASP.NET Web Forms Application name:Interf ...
- MySQL安装之“测试”
将MySQL安装完成之后还需要对其进行测试,判断MySQL是否安装成功,MySQL其可视化与我们之前使用过的SQLserver不同.MySQL其中测试方法有两种:一.使用MySQL命令进行测试:二.安 ...