悬赏园豆:10
[已关闭问题]
关闭于 2008-04-24 17:57
<P>我定义一个字符串,想要用游标把他依次读出来,代码如下,不过结果不对,请教我写的代码错那里了? 我想要的结果是:<BR>1<BR>1<BR>2<BR>2</P>
<P>declare @b varchar(20),@name varchar(20)<BR> set @b = ''<BR> set @name = '1,1,2,2'<BR> declare mycursor cursor <BR> for <BR> select @name<BR> open mycursor<BR> fetch mycursor into @name<BR> while @@fetch_status<>-1<BR> if @@fetch_status <>-2<BR> begin<BR> set @b = substring(@name,0,charindex(',',@name))<BR> set @name = substring(@name,charindex(',',@name)+1,len(@name))<BR> print @b<BR> fetch mycursor into @name<BR> end<BR> close mycursor<BR> deallocate mycursor </P>
问题补充:
为什么我这个做法好像只执行了一次,就输出个1?该怎么改?