136 lines
4.8 KiB
Transact-SQL
136 lines
4.8 KiB
Transact-SQL
alter table HJGL_Pipeline_Component add ProductionState int
|
|
Go
|
|
update HJGL_WeldJoint set WeldingMode=task.WeldingMode
|
|
from HJGL_WeldJoint as joint ,HJGL_WeldTask as task
|
|
where task.WeldJointId =joint.WeldJointId and task.WeldingMode !=''
|
|
Go
|
|
update Sys_Menu set SortIndex='105' where MenuId='7FE911EF-616A-4F04-AACD-E53E633A9E86'
|
|
Go
|
|
/****** Object: Table [dbo].[HJGL_Pipeline_ComponentJoint] Script Date: 2023/2/18 16:21:52 ******/
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
|
|
SET ANSI_PADDING ON
|
|
GO
|
|
|
|
CREATE TABLE [dbo].[HJGL_Pipeline_ComponentJoint](
|
|
[Id] [varchar](50) NOT NULL,
|
|
[PipelineComponentId] [varchar](50) NULL,
|
|
[PipelineComponentCode] [varchar](50) NULL,
|
|
[WeldJointId] [varchar](50) NULL,
|
|
[WeldJointCode] [varchar](50) NULL,
|
|
[State] [int] NULL,
|
|
CONSTRAINT [PK_HJGL_Pipeline_ComponentJoint] PRIMARY KEY CLUSTERED
|
|
(
|
|
[Id] ASC
|
|
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
|
) ON [PRIMARY]
|
|
|
|
GO
|
|
|
|
SET ANSI_PADDING OFF
|
|
GO
|
|
|
|
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
/*
|
|
create by shuke.li 2020-9-15
|
|
*/
|
|
create function [dbo].[SplitString]
|
|
(
|
|
@Input nvarchar(max), --input string to be separated
|
|
@Separator nvarchar(max)=',', --a string that delimit the substrings in the input string
|
|
@RemoveEmptyEntries bit=1 --the return value does not include array elements that contain an empty string
|
|
)
|
|
returns @TABLE table
|
|
(
|
|
[Id] int identity(1,1),
|
|
[Value] nvarchar(max)
|
|
)
|
|
as
|
|
begin
|
|
declare @Index int, @Entry nvarchar(max)
|
|
set @Index = charindex(@Separator,@Input)
|
|
|
|
while (@Index>0)
|
|
begin
|
|
set @Entry=ltrim(rtrim(substring(@Input, 1, @Index-1)))
|
|
|
|
if (@RemoveEmptyEntries=0) or (@RemoveEmptyEntries=1 and @Entry<>'')
|
|
begin
|
|
insert into @TABLE([Value]) Values(@Entry)
|
|
end
|
|
|
|
set @Input = substring(@Input, @Index+datalength(@Separator)/2, len(@Input))
|
|
set @Index = charindex(@Separator, @Input)
|
|
end
|
|
|
|
set @Entry=ltrim(rtrim(@Input))
|
|
if (@RemoveEmptyEntries=0) or (@RemoveEmptyEntries=1 and @Entry<>'')
|
|
begin
|
|
insert into @TABLE([Value]) Values(@Entry)
|
|
end
|
|
return
|
|
end
|
|
GO
|
|
|
|
|
|
|
|
DECLARE
|
|
@PipelineComponentId varchar( 50 ),
|
|
@PipelineComponentCode varchar( 100 ),
|
|
@PipelineId varchar( 100 ),
|
|
@QRCode varchar( max ),
|
|
@QRCodeItem varchar( 100 )
|
|
DECLARE cursor_name CURSOR FOR -- 定义游标
|
|
|
|
select PipelineComponentId ,PipelineComponentCode,PipelineId, QRCode from HJGL_Pipeline_Component where QRCode !=''
|
|
|
|
OPEN cursor_name -- 打开游标
|
|
FETCH NEXT FROM cursor_name INTO @PipelineComponentId,@PipelineComponentCode,@PipelineId ,@QRCode -- 抓取下一行游标数据
|
|
WHILE @@FETCH_STATUS = 0 --(-1 语句失败, -2 被提取行不存在)
|
|
BEGIN
|
|
|
|
DECLARE QRCodeList CURSOR FOR -- 定义游标
|
|
select value from [dbo].[SplitString](@QRCode, ';', 0)
|
|
OPEN QRCodeList -- 打开游标
|
|
FETCH NEXT FROM QRCodeList INTO @QRCodeItem -- 抓取下一行游标数据
|
|
WHILE @@FETCH_STATUS = 0 --(-1 语句失败, -2 被提取行不存在)
|
|
BEGIN
|
|
DECLARE @jointcount int;
|
|
DECLARE @WeldJointId varchar( 100 ) ;
|
|
DECLARE @WeldJointCode varchar( 100 )
|
|
set @jointcount= (select COUNT (*) from HJGL_WeldJoint where PipelineId =@PipelineId and WeldJointCode = SUBSTRING(@QRCodeItem,2,LEN(@QRCodeItem)-1) )
|
|
set @WeldJointId= (select WeldJointId from HJGL_WeldJoint where PipelineId =@PipelineId and WeldJointCode =SUBSTRING(@QRCodeItem,2,LEN(@QRCodeItem)-1))
|
|
set @WeldJointCode= (select WeldJointCode from HJGL_WeldJoint where PipelineId =@PipelineId and WeldJointCode =SUBSTRING(@QRCodeItem,2,LEN(@QRCodeItem)-1))
|
|
--print @QRCodeItem
|
|
if @jointcount>0
|
|
begin
|
|
DECLARE @ComponentJointcount int;
|
|
set @ComponentJointcount=(select COUNT (*) from HJGL_Pipeline_ComponentJoint where WeldJointId= @WeldJointId)
|
|
if @ComponentJointcount>0
|
|
begin
|
|
print '更新焊口'+@WeldJointCode
|
|
update HJGL_Pipeline_ComponentJoint set PipelineComponentId=@PipelineComponentId,PipelineComponentCode =@PipelineComponentCode where Id in (select Id from HJGL_Pipeline_ComponentJoint where WeldJointId= @WeldJointId );
|
|
end
|
|
else
|
|
begin
|
|
print '插入焊口'+@WeldJointCode
|
|
insert into HJGL_Pipeline_ComponentJoint values(NEWID(),@PipelineComponentId,@PipelineComponentCode,@WeldJointId,@WeldJointCode,0)
|
|
end
|
|
end
|
|
FETCH NEXT FROM QRCodeList INTO @QRCodeItem
|
|
END
|
|
CLOSE QRCodeList -- 关闭游标
|
|
DEALLOCATE QRCodeList -- 释放游标
|
|
|
|
FETCH NEXT FROM cursor_name INTO @PipelineComponentId,@PipelineComponentCode,@PipelineId ,@QRCode
|
|
END
|
|
CLOSE cursor_name -- 关闭游标
|
|
DEALLOCATE cursor_name -- 释放游标 |