记录我第一次写sql server 2005的存储过程
来源:互联网 发布:淘宝无线端短连接 编辑:程序博客网 时间:2024/05/16 05:46
使用了递归和临时表,传递了参数,发上来,权当纪念。
USE [UFDATA_005_2014]
GO
/****** 对象: StoredProcedure [dbo].[PROC_PRODUCTTRACING] 脚本日期: 07/05/2017 08:37:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[PROC_PRODUCTTRACING]
-- Add the parameters for the stored procedure here
@autoid varchar(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @cPB nvarchar(60)
declare @cMB nvarchar(60)
declare @cSwCode nvarchar(30)
declare @cInvCode nvarchar(30)
declare @count int
declare @cNumber nvarchar(200)
declare @cSubNumber nvarchar(30)
-- Insert statements for procedure here
select @cInvCode=cInvCode from v_erp_CompletionOrder_sun where autoid=@autoid
if @cInvCode like 'DX%' OR @cInvCode like 'AX%' OR @cInvCode like 'NAX%' OR @cInvCode like 'CTDX%'
begin
print'galvanization or colordraw.....'
select @count=Count(*), @cMB=cMBatch from V_app_GalvanizationCompletion_all where autoid =@autoid GROUP BY cMBatch
print @count
if (@count>0)
begin
print'into galvanization...'
select @cSubNumber=cSubNumber,@cSwCode=cSwCode from v_erp_CompletionOrder_sun
where autoid=@autoid
select * into #temp_q from (select * from v_erp_CompletionOrder_sun a where @autoid=autoid) T
print @cSubNumber
select @cNumber=Value from [UFDATA_005_2014].[dbo].[BG_SplitTextToStringArray](@cSubNumber,'-')where Idx='0'
print @cNumber
select @cMB=cMBatch from V_app_GalvanizationFeeding_all where cNumber=@cNumber and cSwCode=@cSwCode
print @cMB print @cSwCode;
while @count>0
begin
insert into #temp_q select * from v_erp_CompletionOrder_sun where cPBatch=@cMB
select @cMB=cMBatch from v_erp_CompletionOrder_sun where cPBatch=@cMB GROUP BY cMBatch
select @count=Count(*) from v_erp_CompletionOrder_sun where cPBatch=@cMB
end
end
ELSE
begin
print'into colordraw......'
select @cSubNumber=cSubNumber,@cSwCode=cSwCode from v_erp_CompletionOrder_sun where autoid=@autoid
print @cSubNumber;
select @cNumber=Value from [UFDATA_005_2014].[dbo].[BG_SplitTextToStringArray](@cSubNumber,'-')where Idx='0'
print @cNumber
select @cMB=cMBatch from V_app_ColorDrawFeeding_all where cNumber=@cNumber and cSwCode=@cSwCode
print @cMB;
while @count>0
begin
insert into #temp_q select * from v_erp_CompletionOrder_sun where cPBatch=@cMB
select @cMB=cMBatch from v_erp_CompletionOrder_sun where cPBatch=@cMB GROUP BY cMBatch
select @count=Count(*) from v_erp_CompletionOrder_sun where cPBatch=@cMB
end
end
end
ELSE
BEGIN
with TEST_ETC
AS (
SELECT v_erp_CompletionOrder_sun.* from v_erp_CompletionOrder_sun where autoid=@autoid
UNION ALL
SELECT v_erp_CompletionOrder_sun.* from v_erp_CompletionOrder_sun ,TEST_ETC wherev_erp_CompletionOrder_sun. cPBatch=TEST_ETC.cMBatch
)
select * from TEST_ETC;
END
select * from #temp_q
drop table #temp_query;
END
- 记录我第一次写sql server 2005的存储过程
- sql server存储过程的笔记记录
- 第一次写的存储过程
- 第一次写的存储过程
- sql server写存储过程
- 第一次写存储过程
- Delphi写的SQL Server扩展存储过程
- sql server 下写net函数,存储过程的方法
- SQL Server中如何写存储过程
- SQL Server中如何写存储过程
- SQL Server中如何写存储过程
- SQL Server中如何写存储过程
- SQL Server 存储过程返回记录集
- sql server存储过程学习记录
- sql server 2008 存储过程排序记录
- SQL Server学习记录之存储过程
- 第一次写这么长的存储过程,存下来记录下
- 记录一个SQL Server 2005的存储过程,循环修改数据例子
- js学习笔记
- 生成对抗网络学习笔记5----DCGAN(unsupervised representation learning with deep convolutional generative adv)的实现
- 一些关于状压dp的杂七杂八的东西
- 【bzoj2190】【仪仗队】欧拉函数+线性筛(浅尝ACM-J)
- opencv中常用的非线性滤波器--中值滤波medianBlur() 和 双边滤波bilateralFilter()
- 记录我第一次写sql server 2005的存储过程
- 光电隔离RS485典型电路
- 人工神经网络模型与分类
- 《尚学堂科技_马士兵_JAVA_系列视频教程_BBS_2007》学习
- C/C++语言 二维数组作为函数的参数总结
- 1.1 机器学习与Python
- Toast实现源码解析
- EffectiveJava学习1
- 命令获取sql语句的执行计划