Need help with SQL statement
Posted in 1998
I trying to summarize data from a table that has the following structure: acctkey char(18) gldtype char(1) gldyear decimal(2,0) actbbal decimal(17,2) actb1 decimal(17,2) actb2 decimal(17,2) actb3 decimal(17,2) actb4 decimal(17,2) actb5 decimal(17,2) actb6 decimal(17,2) actb7 decimal(17,2) actb8 decimal(17,2) actb9 decimal(17,2) actb10 decimal(17,2) actb11 decimal(17,2) actb12 decimal(17,2) These are account balances stored for each accounting period, corresponding to the months of the year. Each actbX holds the account balance for that period. I want to have a dynamic sql statement that will allow me to loop through and sum all of the numbers in a certain actbX period based on a given month. In otherwords, I want my statement to look something like this: select sum(actbX) into acctbal from tablename The actbX needs to be dynamic. I need to be able to build a statement that will have the period I want to summarize included in it. Unfortunately, PREPARED statements won't work for this because you cannot use the INTO varible clause with them. Can anyone out there suggest a good way to do this other then using a long CASE statement? Any help will be much appreciated. Jon Gjerset jwg@nuera.com