I've been failing in executing a complicated select which joins two large tables. When tried to execute it for a specific record of the first table, it runs perfectly and fast. I tried to collect statistics and use all other, known to me, optimizing methods, with no success.
Is there a way, as part of a regular query (if not, then as part of a stored procedure) to use a 'for each' logic? If I could run through each row on the first table, and for each execute the query, my problem would be solved.