A computed column generates a piece of T-SQL code, therefore the first step is designing the T-SQL code that you want to generate. Only then write X code to actually generate it.
In the other thread, the goal was summarizing data from several records (based on a condition). Therefore the T-SQL code would be something like this:
select sum(Weight) from Inventory
where ...
I don't know your actual requirements here - the code that you showed us above doesn't even aggregate data in any way.
If you want to sum amount by grouped by month and put it into a temporary table, follow Nikolaos's suggestion. Create a computed column for the month number, group by it, iterate records and put individual values to the right fields of your temporary buffer.
Using the twelve computed columns allow you to eliminate the temporary table - you'll simply put the view to a form and all data will be fetched directly from database. I can't say whether it's useful in your particular scenario or not.
The T-SQL code to generate would look like this:
select sum(salary) from MyTable
where month(date) = ...
Which can be generated by code like this:
static str salarySql(int _monthIdx)
{
str pattern = select sum(%1) from %2 where month(%3) = %4;
str salaryField = ...
str tableName = ...
str dateField = ...
return strFmt(pattern, salaryField, tableName, dateField, _monthIdx);
}
I see that you used values like 'Jan' just as field aliases, which we don't need, therefore the month index is the only necessary parameter. You would use field labels to provide user-friendly names for the view fields.