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 <
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.