let it be
行到水穷处 坐看云起时

字符串的截取,在此提供两种方式:
一种使用C#语言的split()函数
另一种使用存储过程来实现
(一)使用split()函数
string str="1/2/3/444/3333/222/5555/";
string[] arr_str;
arr_str=str.split('/')
for(int i=0;i<arr_str.Length;i++)
{
       Response.Write(strData[i]+"<br/>");
}

(二)使用存储过程
--将字符串分割后存放在临时表中,然后将数据返回!
ALTER procedure [dbo].[ZXKS_KS_getjzxx]
@jzbh int
as
--创建临时表,用来保存试题编号
create table temp_table
(
 id int IDENTITY(1,1) primary   key,
 stid int
)
DECLARE @object_id      nvarchar(500)
DECLARE @i    INT
DECLARE @len   INT   
Declare @string   nvarchar(500)
--根据卷子编号获取试题编号字符串
set @string =(select stid from ks_jzxx where jzid=@jzbh)
--将试题编号字符串进行拆分,然后放在临时表中

IF (@string IS NULL) OR (LTRIM(@string) = '')
 RETURN
WHILE CHARINDEX('/',@string) > 0
BEGIN
     SET @len = LEN(@string)
     SET @i = CHARINDEX('/', @string)
     SET @object_id = LEFT(@string, @i-1)
     INSERT INTO temp_table (stid) VALUES (@object_id)--少做修改,改成需要的sql语句即可
     SET @string = RIGHT(@string, @len - @i)
END
select * from temp_table


posted on 2008-05-09 09:01  流浪浪  阅读(591)  评论(0编辑  收藏  举报