November 10th, 2003, 03:59 AM
I have written a stored procedure with a cursor, to loop a distinct set of names and grab associated data on them
How can I insert summed columns in a stored procedure, for example,
if i declare @total as an integer and then do select @total = sum(field)
if i then try an insert into statement, with @total - it does not allow me to execute.
whats the best way to get around this and can anybody explain the reasons why this doesnt work, im sure there are good ones!
November 10th, 2003, 04:11 AM
You probably don't need a cursor at all. It sounds like what you are trying to do could be accomplished by
If you need further help you have to shed some more details.
insert into <your table>
select name,sum(field) from <your joined tables>
group by name
November 10th, 2003, 04:18 AM
ok, my cursor selects 1 distinct name from a view.
then, for each distinct name thats returned, im selecting data from another table for that name.
this works perfectly - but, i want to insert summed fields into a new table, rather than just display them