How do you specify 'DEFAULT' as a SQL parameter value in ADO.NET?

前端 未结 5 2336
礼貌的吻别
礼貌的吻别 2020-12-10 12:08

I have a parameterized SQL query targetted for SQL2005 which is dynamically created in code, so I used the ADO.NET SqlParameter class to add sql parameters to <

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 12:39

    AFAIK, the only way to tell SQL Server to use a default value is via the DEFAULT keyword or to exclude it from parameter list. That means that the use of the DEFAULT keyword must be in your parameterized SQL Statement. So, something like:

    Select ...
    From dbo.udf_Foo( DEFAULT, @Param2, @Param3, DEFAULT, .... )
    

    I suppose another approach would be to query the system catalogs for the actual value of the various DEFAULT values and determine whether to set the SqlParameter to the default value that way, but that requires a convoluted second query to get the default values.

提交回复
热议问题