码迷,mamicode.com
首页 > 数据库 > 详细

SQL之存储过程,仿数组

时间:2016-05-13 13:32:29      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

 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,;

 

SQL之存储过程,仿数组

标签:

原文地址:http://www.cnblogs.com/anwser-jungle/p/5487498.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!