Stephen Forero
asked on
foreach in SQL
Hi all,
I want to run a SP (shown below)...
for every row in
SELECT * FROM mainDB WHERE X = 'hi'
(say for example this brings in 2000 rows)
feeding in 2 columns of variables...
STORED PROCEDURE......
can someone point me in the right direction?
I see things online like PIVOT/CURSOR/ROWNEXT..
thanks
I want to run a SP (shown below)...
for every row in
SELECT * FROM mainDB WHERE X = 'hi'
(say for example this brings in 2000 rows)
feeding in 2 columns of variables...
STORED PROCEDURE......
EXEC dbo.DailyPositions_ProductContractTimePeriod
@Product = (COLUMN1 of main select statement),
@AccountID = 'D6323759-1E95-4354-85A1-7040EA6F5FD8',
@ContractDate = (COLUMN2 of main select statement),
@StartDate = '20130510',
@EndDate = '20130510'
can someone point me in the right direction?
I see things online like PIVOT/CURSOR/ROWNEXT..
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks guys... appreciate the help
1 get 1st record in a table.
2 assign: @c1 to col1 and @c2 to col2 of this record.
3 Use @c1, @c2 in some operation.
4 move to next record
5 repeat from step 2 until end of records.
Is this correct?