开发者

SQL Cursor value in single group

开发者 https://www.devze.com 2022-12-17 18:19 出处:网络
I am using a SQL cursor. I want to select the values While(@@fetchstatus ==0) BEGIN if(cond) SELECT rownumber, rowname FROM TABLE

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

精彩评论

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