I have database that has 12 columns of numeric data - one column for each month.
Column names are
Jan, Feb, Mar. Apr, May, Jun, Jul, Aug, Sep, Oct, Nov and Dec.
I know how to write code to sum first 3 months (Jan, Feb, and Mar) and return value in Total.
SELECT Jan+Feb+Mar AS Total FROM MyData
Question: How do I write generic query to give me sum of first N months?
Do I need to write code to generate the SQL statement or is there another way?
WHEREclause, without having to resort to dynamic SQL.(month, value)and 12 rows, it would be trivial. Having these types of issues is a symptom of a design that's not a SQL Pattern.