views:

38

answers:

1

Hi All,

I'm probably missing something (looking at it too long), but in a stored procedure can I select all distinct values from one table and then do a for each loop based on each of those returned rows, which themselves build up sql statements based on the distinct values?

Cheers.

+5  A: 

Yes, you can use a cursor.

Note that cursors are best avoided if possible. If it's possible to do what you need with a set-based query -- and it often is -- then you should do that instead.

LukeH
This is the correct answer. Nevertheless, this kind of requirement usually points to some more general problem in your (@mailman1979) architecture or code.
Lucero
Hi, Cheers for your answers. In the end I managed to use a set based query.
mailman1979