SQL之存储过程,仿数组

 1 create procedure update_ERPTreeList(@s1 varchar(1000),@s2 varchar(1000))
 2 As
 3 Begin 
 4     declare @ss1 varchar(50),@ss2 int,@ss2_temp varchar(50);
 5     declare @ix1 int,@ix2 int,@pos1 int,@pos2 int;
 6     set @pos1=1;set @pos2=1;set @ix1=1;set @ix2=1;
 7     while (@ix1>0 and @ix2>0)
 8     Begin 
 9         set @ix1=CHARINDEX(',',@s1,@pos1);
10         set @ix2=CHARINDEX(',',@s2,@pos2);
11         if(@ix1>0 and @ix2>0)
12         begin 
13             set @ss1=SUBSTRING(@s1,@pos1,@ix1-@pos1);
14             set @ss2_temp=SUBSTRING(@s2,@pos2,@ix2-@pos2);
15             set @ss2=CAST(@ss2_temp as int);
16             update     [CSPostOA].[dbo].[ERPTreeList] set [TextStr]=@ss1
17             where [ID]=@ss2;
18         end
19         else
20         begin
21             set @s1=SUBSTRING(@s1,@pos1,LEN(@s1)); set @s2=SUBSTRING(@s2,@pos2,LEN(@s2));
22         end
23         set @ss1=LTRIM(RTRIM(@ss1)); set @ss2=LTRIM(RTRIM(@ss2));    
24         set @pos1=@ix1+1; set @pos2=@ix2+1;
25     End
26 End
27 
28 Exec update_ERPTreeList 
29       @s1='任务管理,当前任务,当前发布任务,当前监督任务,历史任务,历史发布任务,历史监督任务,'
30     , @s2='265,266,267,268,269,270,271,';

 

posted @ 2016-05-12 21:51  ~Jungle  Views(1387)  Comments(0Edit  收藏  举报