What are you trying to achieve that you can't already do with a set of
IF statements?
My logic is that when some event occured (param1) then i need to
update some field.
I understand that's what you want to do. I don't understand WHY you
would want to do it. Each column is supposed to represent a different
attribute. I find it difficult to think of a scenario where what you
have said would make much sense - except for the obvious case where you
have a poor table design with a repeating group of columns that you
reference by an index value (param1). In that case the best solution
would be to redesign the table.
Another possibility is that you want to parameterize column names as an
additional level of abstraction to promote code re-use in your SPs.
That's not generally a good strategy - at least not, I think, one that
most people would recognize as best practice. Columns are identified by
column name. For reasons of performance, reliability and ease of
maintenance the practice commonly adopted is to create a separate SP
for each distinct type of update - not necessarily for each unique set
of columns that will be updated but at least with a fixed set of input
parameters that correlate with a fixed set of columns. This is
particularly important for parameters used in the WHERE clause of an
UPDATE statement. It ensures that SQL Server can choose and re-use the
best execution plan for the proocedure.
If you still want to consider other possibilities you may want to look
at Dynamic SQL:
http://www.sommarskog.se/dynamic_sql.html
If you aren't already familiar with dynamic SQL then make sure you read
that whole article and understand the full implications.
Hope this helps.
--
David Portas
SQL Server MVP
--