Insert default value when parameter is null

后端 未结 16 2546
遥遥无期
遥遥无期 2020-12-24 05:27

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

16条回答
  •  半阙折子戏
    2020-12-24 05:59

    You can use the COALESCE function in MS SQL.

    INSERT INTO t ( value ) VALUES( COALESCE(@value, 'something') )

    Personally, I'm not crazy about this solution as it is a maintenance nightmare if you want to change the default value.

    My preference would be Mitchel Sellers proposal, but that doesn't work in MS SQL. Can't speak to other SQL dbms.

提交回复
热议问题