Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Apply results from a stored procedure to multiple rows

Posted on 2009-04-07
2
Medium Priority
?
201 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:quilkin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 22

Expert Comment

by:pivar
ID: 24085803
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

0
 
LVL 22

Accepted Solution

by:
pivar earned 1500 total points
ID: 24085827
Or with your code, picking up the value with select before using it with your sp. Declare @referenceValue and assign from proper column
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
    select @referencValue=(?) from Details where col1 = @count
    -- 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

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question