I'm working on a procedure that needs to cycle through the records of some raw data and combine the the current record with the datetime field of the prior record. I have been able to write a script to do that with cursors and variables but my problem is it returns each record separately. How do I go about getting the procedure to return all the records as one set of data?
To see what I mean, the following script for the Pubs DB returns each pass through the data as a seperate query. Since I can't do a select *, what approach should I take? If you want the actual script, I would be happy to provide it.
DECLARE authors_cursor CURSOR
FOR SELECT * FROM authors
OPEN authors_cursor
FETCH NEXT FROM authors_cursor
WHILE @.@.FETCH_STATUS = 0
begin
FETCH NEXT FROM authors_cursor
end
Close Authors_cursor
deallocate authors_cursor
Thanks in advance
Tony Murunion
If you only need the previous value, the best thing would be to store the previous data in a local variable. I think that is a common approach.HTH, jens Suessmeyer.
http://www.sqlserver2005.de
|||
Thanks for the reply
The actual script I was working with used local variables to get the data I wanted. I was just stuck with getting the results back in one set instead of one for each record.
I was able to resolve my problem by dumping the data into a table in a function (decided to try that instead of a proc)
Tony
No comments:
Post a Comment