I am using SQL Server 2000. I have a table with, say, 20 columns. I
have one procedure which updates all 20 columns at once, accepting a
parameter for each column. However, I want to be able to pass any
combination of parameters and only update those columns if passed. So
I created the sp as something like
create update_t1
(
@col1 int = null,
@col2 int = null,
@col3 int = null,
....
@col20 int = null
)
as
update t1
set col1 = @col1,
col2 = @col2,
col3 = @col3,
.....
col20 = @col20
This way I can explicitly specify columns or not as I choose. For
example I could call "exec update_t1 @col1 = 23, @col4 = 49" to update
only the first and fourth column. Of course this will obviously
update the remaining columns to null. Is there any way to identify
within the procedure which parameters were actually specified? I
can't simply do a null check because the user could be updating the
value to be null. Is there any way for the procedure to know the
exact command that invoked it?
For example, if I called "exec update_t1 @col1 = 23, @col4 = 49" I
would want to know only col1 and col4 were specified. If I called
"exec update_t1 @col1 = 23, @col4 = 49, @col17 = null" I would want to
know that col1, col4 and col17 were specified, even though col17 was
set to the default of null.
have one procedure which updates all 20 columns at once, accepting a
parameter for each column. However, I want to be able to pass any
combination of parameters and only update those columns if passed. So
I created the sp as something like
create update_t1
(
@col1 int = null,
@col2 int = null,
@col3 int = null,
....
@col20 int = null
)
as
update t1
set col1 = @col1,
col2 = @col2,
col3 = @col3,
.....
col20 = @col20
This way I can explicitly specify columns or not as I choose. For
example I could call "exec update_t1 @col1 = 23, @col4 = 49" to update
only the first and fourth column. Of course this will obviously
update the remaining columns to null. Is there any way to identify
within the procedure which parameters were actually specified? I
can't simply do a null check because the user could be updating the
value to be null. Is there any way for the procedure to know the
exact command that invoked it?
For example, if I called "exec update_t1 @col1 = 23, @col4 = 49" I
would want to know only col1 and col4 were specified. If I called
"exec update_t1 @col1 = 23, @col4 = 49, @col17 = null" I would want to
know that col1, col4 and col17 were specified, even though col17 was
set to the default of null.
Comment