sql - Dynamic "column" update in mysql with respect to parameter of procedure -
i want update column of table t1
in procedure called my_proc(param)
. want this:
if param=1 update t1 set c1="some value" if param=2 update t1 set c2="some value" if param=3 update t1 set c3="some value" ...
cnn suggest, should appropriate approach?
your code right. correct syntax is:
if param = 1 update t1 set c1 = 'some value'; elseif param = 2 update t1 set c2 = 'some value'; elseif param = 3 update t1 set c3 = 'some value' end if;
if like, write 1 update
:
update t1 set c1 = (case when param = 1 'some value' else c1 end), c2 = (case when param = 2 'some value' else c2 end), c3 = (case when param = 3 'some value' else c3 end);
Comments
Post a Comment