I am working on a table that has 24 columns named pp1, pp2… pp24.
I would like to pass in a parameter that would be used to help identify the column to be updated.
- one parameter is the value (8)
- one parameter is the column (5)
- one parameter is the rowID (256)
short stored proc…
update 'pp'+ [column_parameter]
set value to [value_parameter]
where rowID = [rowID_parameter]
Can the concatenation of the partial column name be combined with a parameter?
Best Answer
That's really a bad idea, I don't understand why you need to do so, and it can't be done the way you are looking for, but if you going to do this, I suggest to declare 24 variable + 1 for the
RowID
.For example:
Then call your procedure, and pass
NULL
s for columns you don't want to be updated. That's the only way I can think of it.Sample Demo
UPDATE:
You don't even need for DynamicSQL, so your
SP
may looks like