SQL之存储过程,仿数组

时间:2022-07-21 07:12:04
 create procedure update_ERPTreeList(@s1 varchar(),@s2 varchar())
As
Begin
declare @ss1 varchar(),@ss2 int,@ss2_temp varchar();
declare @ix1 int,@ix2 int,@pos1 int,@pos2 int;
set @pos1=;set @pos2=;set @ix1=;set @ix2=;
while (@ix1> and @ix2>)
Begin
set @ix1=CHARINDEX(',',@s1,@pos1);
set @ix2=CHARINDEX(',',@s2,@pos2);
if(@ix1> and @ix2>)
begin
set @ss1=SUBSTRING(@s1,@pos1,@ix1-@pos1);
set @ss2_temp=SUBSTRING(@s2,@pos2,@ix2-@pos2);
set @ss2=CAST(@ss2_temp as int);
update [CSPostOA].[dbo].[ERPTreeList] set [TextStr]=@ss1
where [ID]=@ss2;
end
else
begin
set @s1=SUBSTRING(@s1,@pos1,LEN(@s1)); set @s2=SUBSTRING(@s2,@pos2,LEN(@s2));
end
set @ss1=LTRIM(RTRIM(@ss1)); set @ss2=LTRIM(RTRIM(@ss2));
set @pos1=@ix1+; set @pos2=@ix2+;
End
End Exec update_ERPTreeList
@s1='任务管理,当前任务,当前发布任务,当前监督任务,历史任务,历史发布任务,历史监督任务,'
, @s2='265,266,267,268,269,270,271,';