CURSOR usage in SQL - in a nested Select statement

Is this OK or possible to do:

declare mycur cursor for
  select ...
      select ....
      from ...  where ...
   ) a
  where ...
  order by... etc

I think this will work, but I am not sure about things like performance or semantic errors?
Who is Participating?
gplanaConnect With a Mentor Commented:
The preformance issues related to a subselect on from clause are related to the fact that the resolt of the inner select can't be indexed. So if the outer where is not very selective, it is ok; but if the inner select returns millions ofregisters and the outer where filters these millions of registers to just a hunderds of them, then the performance is not good.

Hope it is a little clear now.

It will work. However, sometimes is not the best performance option.

Maybe if you can explain a little more we can help you more.

CodeWranglerAuthor Commented:
Well, the issue is with the source data... we need to combine some varchar values into 1 value because of character positioning and then do a group by on that result set.. hence the select from (select...). What performance issues you think?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.