I have a table that has a column with a default value:
create table t (
value varchar(50) default ('something')
)
I'm using a stored procedure to insert values into this table:
create procedure t_insert (
@value varchar(50) = null
)
as
insert into t (value) values (@value)
The question is, how do I get it to use the default when @value is null? I tried:
insert into t (value) values ( isnull(@value, default) )
That obviously didn't work. Also tried a case statement, but that didn't fair well either. Any other suggestions? Am I going about this the wrong way?
Update: I'm trying to accomplish this without having to:
- maintain the
defaultvalue in multiple places, and - use multiple
insertstatements.
If this isn't possible, well I guess I'll just have to live with it. It just seems that something this should be attainable.
Note: my actual table has more than one column. I was just quickly writing an example.