you need to send NULL to the database, but for some reason microsoft has invented DBNull.Value
in c#
Here is an example of calling your function in c#
DateTime? beginDate = null;
DateTime? endDate = DateTime.now;
using (SqlCommand command = new SqlCommand("select * from FnEmployeeProduction (@begin, @end)");
{
command.Parameters.Add("@begin", SqlDbType.DateTime).Value = (beginDate == null) ? (object)DBNull.Value : beginDate;
command.Parameters.Add("@end", SqlDbType.DateTime).Value = (endDate == null) ? (object)DBNull.Value : endDate;
// now you can use this command object to send to your DB
using (SqlConnection connection = new SqlConnection(your conn string))
{
connection.Open();
command.Connection = connection;
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
adapter.Fill(your datatable);
}
}
}
And inside your function you need to handle null values off course
create function FnEmpoyeeProduction (@begin datetime, @end datetime) as
begin
if @begin is not null
begin
end
and so on...
end