Skip to content
Advertisement

Stored procedure to select values in table1, Group By, Sum, then insert those values into table2

I need a stored procedure to select rows from one table, do a Group By, Sum, and then insert the results into another table with their values.

I guess I’ll have to do a merge when rfds_processing_id (similar to an order number) matches existing rows, and insert when it doesn’t. I am currently doing something similar in Linq in my controller, but can’t figure it out in SQL.

This is what I’m doing in my Controller and sending to my View

Here’s the update for the first part that is working correctly

Advertisement

Answer

Your current proc looks OK to me, except that the GROUP BY clause should contain all non aggregate columns which also appear in the SELECT:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement