tags:

views:

42

answers:

3

I have a temporary table (or, say, a function which returns a table of values).

I want to execute some statements for each record in the table. Can this be done without using cursors?

I'm not opposed to cursors, but would like a more elegant syntax\way of doing it.

Something like this randomly made-up syntax:

for (select A,B from @temp) exec DoSomething A,B

I'm using Sql Server 2005.

+1  A: 

I dont think what you want to to is that easy.

What i have found is that you can create a scalar function taking the arguments A and B and then from within the function execute an Extended Stored Procedure. This might achieve what you want to do, but it seems that this might make the code even more complex.

I think for readibility and maintainability, you should stick to the CURSOR implementation.

astander
Yes, I think you're right. I've looked around and cursors are pretty much the standard way of doing it.
HS
A: 

I would look into changing the stored proc so that it can work against a set of data rather than a single row input.

AdamRalph
A: 

Would CROSS/OUTER APPLY do what you want if you need RBAR processing.

It's elegant, but depends on what processing you need to do

gbn