--临时表
IF OBJECT_ID('tempdb..#Entry') is not null
BEGIN
DROP TABLE #Entry
END
-----------------------------------------------------
--创建触发器
ALTER TRIGGER [dbo].[icstockbill_ins]
ON [dbo].[ICStockBill]
AFTER insert
AS
BEGIN
SET NOCOUNT ON;
declare @ftrantype int,@Finterid int
declare @text varchar(255)
declare @fbillerid int
select @ftrantype=ftrantype,@Finterid=finterid from inserted
问
if @ftrantype=1
begin
exec [采购申请单执行信息更新] @Finterid
end
end
--------------------------------------------------------------
--创建存储过程
ALTER PROC lj_bom_wanjue @fitemid int ,@flevel int
AS
begin
DECLARE CURSOR FOR
SELECT FITEMID,FQTY INTO #tmp FROM dbo.BZX_BOMEntry WHERE FID =
(SELECT MAX(fid) FROM dbo.BZX_BOM WHERE FITEMID = @fitemid)
SELECT *FROM #tmp
DROP TABLE #tmp
END
EXEC lj_bom_wanjue 78940, 1
----------------------------------------------------
--游标
CREATE table #t(fitemid INT)
DECLARE @fitemid INT
DECLARE lj_test CURSOR FOR
SELECT TOP 50 FItemID FROM dbo.t_ICItem
OPEN lj_test
FETCH NEXT FROM lj_test INTO @fitemid
while (@@fetch_status=0)
BEGIN
INSERT INTO #t(fitemid) VALUES (@fitemid)
--PRINT @fitemid
FETCH NEXT FROM lj_test INTO @fitemid
END
CLOSE lj_test
DEALLOCATE lj_test
SELECT *FROM #t
DROP TABLE #t
------------------------------------------------------------
--BOM嵌套
declare @lev int,@liaohao varchar(30)
select @MID='2',@levs=1
declare @t table(物料ID号 varchar(30),序号 int,物料父ID号 varchar(30),levs int)
insert @t select 物料ID号 ,序号,物料父ID号,@levs from BOM where 物料ID号=@lMID
while @@rowcount<>0
begin
set @levs=@levs+1
insert @t select 物料ID号,序号,物料父ID号,@levs from BOM
where 物料父ID号 in(select 物料ID号 from @t where levs=@levs-1)
end
select * from @t order by levs
---------------------------------------------------------------
--临时表
insert into #bzxbom(fmbitemid,fitemid,fqty,fyt,fth,fisty,fgx,fnote,flev,fismm,fpz ) select @fcpitmeid,@fitemid,@fqty,@fyt,@fth,@fisty,@fyt,@FNOTE,cast(@fmb as varchar(255)),@fismm,@fpz
if exists(select 1 from BZX_BOM where FITEMID = @fitemid )
-------------------------------------------------------------
--存储过程调用存储过程
exec GetICMaxNum 'icstockbill' ,@fqoutinterid output ,1,@fbiller
exec LJ_GetBillNo 29,@fqoutbillno output
select @fqoutinterid as finterid,IDENTITY(int,1,1) as fentryid,'0' as fbrno,a.FItemID,a.FBatchNo,a.FQty,a.FStockID,b.FUnitID,a.FQty as Fauxqty,'PLM调拨库存' as fnote,a.FStockPlaceID,14036 as FPlanMode
into #lj_qout
from ICInventory a inner join t_ICItem b on a.FItemID =b.FItemID
where b.FNumber = @foldnumber and b.FDeleted =0 and a.FQty >0
INSERT INTO ICStockBillEntry (FInterID,FEntryID,FBrNo,FItemID,FBatchNo,FQty,FDCStockID,FUnitID,Fauxqty,Fnote,FDCSPID,FPlanMode)
SELECT * from #lj_qout
drop table #lj_qout
INSERT INTO ICStockBill(FInterID,FBillNo,FBrNo,FTranType,FCancellation,FStatus,FUpStockWhenSave,FROB,Fdate,FDeptID,Fuse,FCheckDate,FFManagerID,FSManagerID,FBillerID,FHeadSelfB0941 )
SELECT @fqoutinterid,@fqoutbillno,'0',29,0,0,0,1,convert(varchar(10),GETDATE(),120),65522,'',Null,10147,10147,16740,@fplmwldh
EXEC p_UpdateBillRelateData 29,@fqoutinterid,'ICStockBill','ICStockBillEntry'
----------------------------------------------------------
--存储过程返回值
ALTER proc [dbo].[LJ_GetBillNo]
@ClassType VARCHAR(50),
@RBillNo VARCHAR(50) OUTPUT
AS
BEGIN
DECLARE @BillNo varchar(50)
DECLARE @FullBillNo varchar(50)
DECLARE @BillID int
DECLARE @TmpID INT
DECLARE @BillIDLen int
DECLARE @NOBillStr varchar(5000)
DECLARE @BillStr varchar(5000)
DECLARE @SCRBillNO varchar(500)
SET @FullBillNo = ''
set @BillNo=''
--取单据编号1
SELECT @BillNo = a.fprojectval
FROM t_BillCodeRule a
LEFT OUTER JOIN t_option e ON a.fprojectid = e.fprojectid AND a.fformatindex = e.fid
LEFT OUTER JOIN t_checkproject b ON a.fbilltype = b.fbilltypeid AND a.fprojectval = b.ffield
WHERE a.fbilltypeid = @ClassType
AND a.fprojectID = 1
--取单据编号2
SELECT @BillIDLen = a.flength,
@BillID = a.fprojectval
FROM t_BillCodeRule a
LEFT OUTER JOIN t_option e ON a.fprojectid = e.fprojectid AND a.fformatindex = e.fid
LEFT OUTER JOIN t_checkproject b ON a.fbilltype = b.fbilltypeid AND a.fprojectval = b.ffield
WHERE a.fbilltypeid = @ClassType
AND a.fprojectID = 3
--设置返回值
SET @FullBillNo = (@BillNo + REPLICATE('0' , @BillIDLen - LEN(CAST(@BillID AS VARCHAR(50)))) + CAST(@BillID AS VARCHAR(50)))
BEGIN TRAN
-- 更新流水号
SET @TmpID = (SELECT FID
FROM t_BillCodeRule WITH(READUNCOMMITTED)
WHERE fbilltypeid = @ClassType
AND fprojectid = 3)
UPDATE t_BillCodeRule
SET fprojectval = fprojectval + 1 ,
flength = CASE WHEN (flength - LEN(fprojectval + 1)) >= 0
THEN flength
ELSE LEN(fprojectval + 1)
END
WHERE FID = @TmpID
UPDATE ICBillNo
SET FCurNo = (SELECT TOP 1 ISNULL(fprojectval - 1 , 1)
FROM t_BillCodeRule
WHERE fprojectid = 3
AND fbilltypeid = @ClassType)
WHERE fbillid = @ClassType
-- 更新注释流水号
SET @BillID = @BillID + 1
UPDATE ICBillNo
SET FDesc = @BillNo + '+' + REPLICATE('0' , @BillIDLen - LEN(CAST(@BillID AS VARCHAR(50)))) + CAST(@BillID AS VARCHAR(50))
WHERE FBillID = @ClassType
IF @@error = 0
BEGIN
SELECT @RBillNo = @FullBillNo
COMMIT
END
ELSE
BEGIN
ROLLBACK
SELECT @RBillNo = ''
END
RETURN
END
- sqlserver 常用语法
sqlserver查找 table, view, column select * from information_schema.tables where table_schema='bk' sele ...
- SqlServer常用语法总结
前言 近期公司做一个短信平台,写了一些关于统计方面的存储过程,今天刚好有空总结一下. 统计查询和性能提升 一.使用WITH AS提高性能简化嵌套SQL 首先,感谢@飞洋过海和@宋沄剑,通过阅读他们的博 ...
- Markdown通用的常用语法说明
前言 Markdown 是一种轻量级的 标记语言,语法简洁明了.学习容易,还具有其他很多优点,目前被越来越多的人用来写作使用. Markdown具有一系列衍生版本,用于扩展Markdown的功能(如表 ...
- Markdown简介以及常用语法
Markdown简介以及常用语法 最近发现用markdown记录东西很方便,感觉和emacs的org mode很类似,但是windows下使用emacs不是很方便.特此记录一下markdown常用的语 ...
- Sql常用语法以及名词解释
Sql常用语法以及名词解释 SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) D ...
- Markdown常用语法
什么是Markdown Markdown 是一种方便记忆.书写的纯文本标记语言,用户可以使用这些标记符号以最小的输入代价生成极富表现力的文档. 通过Markdown简单的语法,就可以使普通文本内容具有 ...
- 2 hive的使用 + hive的常用语法
本博文的主要内容有: .hive的常用语法 .内部表 .外部表 .内部表,被drop掉,会发生什么? .外部表,被drop掉,会发生什么? .内部表和外部表的,保存的路径在哪? .用于创建一些临时表存 ...
- sql 常用语法汇总
Sql常用语法 SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL—数据控 ...
- ylb:SQLServer常用系统函数-字符串函数、配置函数、系统统计函数
原文:ylb:SQLServer常用系统函数-字符串函数.配置函数.系统统计函数 ylbtech-SQL Server:SQL Server-SQLServer常用系统函数 -- ========== ...
随机推荐
- Java面试知识点之设计模式(一)
前言:关于设计模式,在框架中用的比较多.在平常接触最为频繁的估计是单例模式了,因此笔者在此对设计模式相关知识点进行总结. 1.设计模式的种类 总体来说,设计模式分为3大类总共23种: 1)创建型模式, ...
- 浅析 PHP 中的 Generator
浅析 PHP 中的 Generator Miss Wang php开发案例 前天 何为 Generator 从 PHP 5.5 开始,PHP 加入了一个新的特性,那就是 Generator,中文译为生 ...
- 正则表达式工具RegexBuddy
1 下载 RegexBuddy 并安装 安装后的界面如下: 2 切换布局 点击右上角的彩色格子图标,选择 Side by Side Layout: 这种布局的好处是,Create 面板 ...
- 【转】Windows系统中ckplayer视频边下边放,视频转码mp4及"last atom in file was not a moov atom"问题
视频转码成mp4格式并添加关键帧: 1.先下载与自己操作系统相对应的的FFmpeg软件.官网传送门:http://ffmpeg.zeranoe.com/builds/ 下载static版的就可以,zi ...
- 第23章 Spring MVC初体验
23.1 鸟瞰Spring MVC 粗略的介绍了SpringMVC的主要组成部分,SpringMVC作为一个Web层的框架,最大的作用是把我从繁重的web.xml文件编写中解救出来,再也不要不停的添加 ...
- ActiveMQ后台使用
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/nangeali/article/details/81514517默认地址 http://192.16 ...
- RMAN_RAC归档日志备份包恢复到单机
恢复归档日志的方法: RAC是ASM的存储且是OMF创建的格式,所以RAC的日志名为如下+ARCH/mioa/archive/1_73554_875548170.dbf.+ARCH/mioa/arch ...
- 极端恢复时用到的几个隐藏参数 Oracle hidden corruption recovery parameters
Oracle hidden corruption recovery parameters Note: Oracle hidden parameters are undocumented and uns ...
- apt-get update 更新 ubuntu时出现Hash sum mismatch的原因及解决方法
$ sudo apt-get update ...... Hit http://mirrors.163.com trusty/main Sources ...
- Spring Security(二十):6.2.3 Form and Basic Login Options
You might be wondering where the login form came from when you were prompted to log in, since we mad ...