Link to home
Start Free TrialLog in
Avatar of quilkin
quilkinFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Apply results from a stored procedure to multiple rows

Hi,

I have a table that I have generated using code similar as below and I would like to perform a stored procedure on all the rows in the table.  What is the best way to approach this?
SELECT col1, col2, col3 
INTO Details 
FROM dbo.CalibrationPoints;
 
ALTER TABLE Details ADD col4 REAL NULL;
 
SELECT @count = count(*) FROM Details;
 
WHILE @count  > 0
BEGIN
    -- EXEC spGetError @error OUTPUT, @calibrationID, referenceValue;
    -- UPDATE Details SET  col4 = @error  where col1 = @count;
    
    SELECT @count = @count -1;
END;
 
DROP TABLE Details;

Open in new window

Avatar of pivar
pivar
Flag of Sweden image

Hi,

You could use a cursor.

/peter
DECLARE yourcursor CURSOR FOR 
SELECT col1, col2, col3 FROM dbo.CalibrationPoints
 
OPEN yourcursor
 
FETCH NEXT FROM yourcursor INTO @col1, @col2, @col3
 
WHILE @@FETCH_STATUS = 0 BEGIN
    --EXEC spGetError @error OUTPUT, @calibrationID, referenceValue
    --UPDATE Details SET col4 = @error  where col1 = @count
 
    FETCH NEXT FROM yourcursor INTO @col1, @col2, @col3
END 
 
CLOSE yourcursor
DEALLOCATE yourcursor

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of pivar
pivar
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial