|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
Stored proc
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!
__________________
_______________ Matt |
|
#2
|
|||
|
|||
|
You probably don't need a cursor at all. It sounds like what you are trying to do could be accomplished by
Code:
insert into <your table> select name,sum(field) from <your joined tables> group by name If you need further help you have to shed some more details. |
|
#3
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Stored proc |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|