日期:2014-05-18  浏览次数:20636 次

小弟不才 请教大家一个简单的问题!请好心人帮忙
代码如下:
declare   Cur_tmp   cursor   for
select   subj_code,flag,row
from   ht_code_flag_table
where   row=@p1
Open   cur_tmp
Fetch     Next   From   Cur_tmp   into   @subj_code,@flag,@row
WHILE   @@FETCH_STATUS   =   0
BEGIN

Fetch     Next   From   Cur_tmp   into   @subj_code,@flag,@row
                          ----含有h的表达式----
if   charindex( 'h ',@subj_code)> 0   and   charindex( '. ',@subj_code) <=0
----取出h所在的行----
set   @row_h   =   cast(substring(LTRIM(@subj_code),2,len(LTRIM(@subj_code))-1)   as   int)

END

close   cur_tmp
deallocate   cur_tmp
数据结果如下

54
61
71
74
81
81
想问   如何把最后一个81忽略掉   或者不显示

------解决方案--------------------
declare Cur_tmp cursor for
select subj_code,flag,row
from ht_code_flag_table
where row=@p1
Open cur_tmp
Fetch Next From Cur_tmp into @subj_code,@flag,@row
WHILE @@FETCH_STATUS = 0
BEGIN


----含有h的表达式----
if charindex( 'h ',@subj_code)> 0 and charindex( '. ',@subj_code) <=0
----取出h所在的行----
set @row_h = cast(substring(LTRIM(@subj_code),2,len(LTRIM(@subj_code))-1) as int)
Fetch Next From Cur_tmp into @subj_code,@flag,@row

END

close cur_tmp
deallocate cur_tmp


//Fetch Next From Cur_tmp into @subj_code,@flag,@row
这句应该放在后面吧