开发者

SQL Cursor value in single group

I am using a SQL cursor. I want to select the values

While(@@fetchstatus ==0)
BEGIN
  if(cond)
    SELECT rownumber, rowname FROM TABLE
END

During the first round of execution of While loop I am getting the value.

1,"Firstrow"(From Row select)

Next

2,"SecondRow"

All these values are displayed in my output as separate rows. Is it possible to combine开发者_开发问答 and display as two outputs like this

1, "FirstRow"

2,"SecondRow"


If you realy need the loop over the cursor, this might be helpful:

-- create temptable
select top 0 rownumber, rowname 
into #temp
from table

-- loop through your cursor
While(@@fetchstatus ==0)
BEGIN
  if(cond)
  begin
    insert into #temp
    SELECT rownumber, rowname FROM TABLE
  end
END

select rownumber, rowname from #temp

drop #temp
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜