My current table structure is 12 column, each representing month.
I need to dynamically select which column to update based on sysdate.
for updation done in january, the query should look like :-
UPDATE report SET jan VALUE = 'blabla'
and for updation done in december, the query should look like :-
UPDATE report SET dec VALUE = 'blabla'
Is there any way to simplify this. Maybe into something like this:-
UPDATE report SET curMonth() VALUE = 'blabla'
A table that has 12 columns with the names of the 12 months is a poor design– it violates basic normalization and creates problems like this where you have to resort to using dynamic SQL. If you had a properly normalized table with one row per month, you could write a simple static SQL statement.
You could do something like this