USE [irepodb]
GO
/****** Object: StoredProcedure [dbo].[P_34#_BOLT] Script Date: 2025/10/30 16:20:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Batch submitted through debugger: SQLQuery24.sql|7|0|C:\Users\jinfeng_xiang\AppData\Local\Temp\~vs3A56.sql
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[P_34#_BOLT]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
declare @val VARCHAR(10),@displayValue VARCHAR(10),@Date VARCHAR(20),@celladdress VARCHAR(15),@rep_top_id VARCHAR(10),@def_top_id VARCHAR(10),
@error int ,@differ VARCHAR(10),@workpiece VARCHAR(10),@specs VARCHAR(10),@orders VARCHAR(10),@time VARCHAR(10),@remarks nvarchar(50) ,@sheetNo VARCHAR(10) ,@def_top_org VARCHAR(10)
set @error=0
INSERT INTO T_BOLT_TREND_B SELECT * FROM T_BOLT_TREND WHERE def_top_id in ('411','10322','21529')
DELETE FROM T_BOLT_TREND WHERE def_top_id in ('411','10322','21529')
-- begin tran --申明事务
declare row_cursor_col cursor
FOR (SELECT distinct displayValue ,celladdress,rep_top_id,def_top_id,sheetNo,def_top_org from [irepodb].[dbo].[T_BOLT]
WHERE (type='InputNumeric' OR type='KeyboardText') AND CONVERT(int ,REPLACE( RIGHT(rtrim(CELLADDRESS), 2),'$','')) >= '6'
and def_top_org in ('411','10322','21529')
and displayValue is not null
)
open row_cursor_col
--开始循环游标变量--
fetch next from row_cursor_col into @displayValue,@celladdress,@rep_top_Id,@def_top_id,@sheetNo,@def_top_org
while @@FETCH_STATUS = 0 --返回被 FETCH语句执行的最后游标的状态--
begin
SELECT @Date=ISNULL(displayValue,0) from [irepodb].[dbo].[T_BOLT] WHERE
type='Date'
AND REPLACE( RIGHT(rtrim(CELLADDRESS), 2),'$','') = '2'
and @rep_top_id = rep_top_id and @def_top_org=def_top_org and @sheetNo=sheetNo
SELECT @workpiece=ISNULL(displayValue,0) from [irepodb].[dbo].[T_BOLT] WHERE
REPLACE(SUBSTRING(CELLADDRESS,2,2),'$','')=REPLACE(SUBSTRING(@celladdress,2,2),'$','') and type='Select' -- and name='班组'
AND REPLACE( RIGHT(rtrim(CELLADDRESS), 2),'$','') = '3'
and @rep_top_id = rep_top_id and @def_top_org=def_top_org and @sheetNo=sheetNo
--G列=71
IF (dbo.getTransCOL(REPLACE(SUBSTRING(@celladdress,2,2),'$',''))-71)%3=1
BEGIN
SELECT @time=ISNULL(displayValue,0) from [irepodb].[dbo].[T_BOLT] WHERE
type='Time' -- and name='时间'
AND REPLACE( RIGHT(rtrim(CELLADDRESS), 2),'$','') = '4'
AND dbo.getTransCOL(REPLACE(SUBSTRING(celladdress,2,2),'$',''))=dbo.getTransCOL(REPLACE(SUBSTRING(@celladdress,2,2),'$',''))+1
and @rep_top_id = rep_top_id and @def_top_org=def_top_org and @sheetNo=sheetNo
SET @differ='最大值'
SELECT @specs=ISNULL(displayValue,0) from [irepodb].[dbo].[T_BOLT] WHERE
--type='KeyboardText' AND
(REPLACE( RIGHT(rtrim(CELLADDRESS), 2),'$','') BETWEEN
CONVERT(INT,REPLACE(SUBSTRING(@celladdress,4,2),':','')) AND CONVERT(INT,REPLACE( RIGHT(rtrim(@celladdress), 2),'$','')))
AND dbo.getTransCOL(REPLACE(SUBSTRING(celladdress,2,2),'$',''))=dbo.getTransCOL(REPLACE(SUBSTRING(@celladdress,2,2),'$',''))+2
and @rep_top_id = rep_top_id and @def_top_org=def_top_org and @sheetNo=sheetNo
SET @orders=(dbo.getTransCOL(REPLACE(SUBSTRING(@celladdress,2,2),'$',''))-69)/3
insert into T_BOLT_TREND (ID,Date,TIME,Workpiece,Differ,DisplayValue,Orders,COL,Specs,updateTime,rep_top_id,def_top_id,sheetNo,Remarks) values(NEWID(),
@Date,@time,@workpiece,@differ,@displayValue,@orders,REPLACE(@celladdress,' ',''),@specs,GETDATE(),@rep_top_id,@def_top_org,@sheetNo,'ZZ')
END
IF (dbo.getTransCOL(REPLACE(SUBSTRING(@celladdress,2,2),'$',''))-71)%3=2
BEGIN
SELECT @time=ISNULL(displayValue,0) from [irepodb].[dbo].[T_BOLT] WHERE
type='Time' -- and name='时间'
AND REPLACE( RIGHT(rtrim(CELLADDRESS), 2),'$','') = '4'
AND dbo.getTransCOL(REPLACE(SUBSTRING(celladdress,2,2),'$',''))=dbo.getTransCOL(REPLACE(SUBSTRING(@celladdress,2,2),'$',''))
and @rep_top_id = rep_top_id and @def_top_org=def_top_org and @sheetNo=sheetNo
SET @differ='最小值'
SELECT @specs=ISNULL(displayValue,0) from [irepodb].[dbo].[T_BOLT] WHERE
(REPLACE( RIGHT(rtrim(CELLADDRESS), 2),'$','') BETWEEN
CONVERT(INT,REPLACE(SUBSTRING(@celladdress,4,2),':','')) AND CONVERT(INT,REPLACE( RIGHT(rtrim(@celladdress), 2),'$','')))
AND dbo.getTransCOL(REPLACE(SUBSTRING(celladdress,2,2),'$',''))=dbo.getTransCOL(REPLACE(SUBSTRING(@celladdress,2,2),'$',''))+1
and @rep_top_id = rep_top_id and @def_top_org=def_top_org and @sheetNo=sheetNo
SET @orders=(dbo.getTransCOL(REPLACE(SUBSTRING(@celladdress,2,2),'$',''))-70)/3
insert into T_BOLT_TREND (ID,Date,TIME,Workpiece,Differ,DisplayValue,Orders,COL,Specs,updateTime,rep_top_id,def_top_id,sheetNo,Remarks) values(NEWID(),
@Date,@time,@workpiece,@differ,@displayValue,@orders,REPLACE(@celladdress,' ',''),@specs,GETDATE(),@rep_top_id,@def_top_org,@sheetNo,'ZZ')
END
-- print @time
-- print @Date
-- print @workpiece
-- print @displayValue
-- print @specs
-- print @celladdress
-- print @rep_top_id
set @error= @error + @@ERROR --记录每次运行sql后是否正确,0正确
fetch next from row_cursor_col into @displayValue,@celladdress,@rep_top_Id,@def_top_id,@sheetNo,@def_top_org --转到下一个游标
end
INSERT INTO T_BOLT_KANBAN
SELECT A.Specs, A.DATE, A.TIME, A.Workpiece, A.Differ, A.COL, CONVERT(DECIMAL(12, 2), A.DisplayValue) AS DisplayValue, A.Orders, A.rep_top_id, A.def_top_id,
A.sheetNo, B.PROJECTID, B.PROJECT, B.ROW, B.BOLT_NUM, B.LINE, B.TEAM, B.TYPE, B.UP_LIMIT, B.DOWN_LIMIT, B.UP_ACTION,
B.DOWN_ACTION,GETDATE() FROM dbo.T_BOLT_TREND AS A LEFT OUTER JOIN
dbo.T_BOLT_LIMIT AS B ON A.def_top_id = B.DEF_TOP_ORG AND B.ROW = REPLACE(RIGHT(RTRIM(A.COL), 2), '$', '')
WHERE DEF_TOP_ORG in ('411','10322','21529') AND ((dbo.getTransCOL(REPLACE(SUBSTRING(A.COL, 2, 2), '$', '')) - 71) % 3 <> 0)
-- if @error=0
--begin
-- commit tran --提交事务
--end
-- else
--begin
-- rollback tran --回滚事务
--end
close row_cursor_col --关闭游标
deallocate row_cursor_col --释放游标
END
优化存储过程
最新发布