I'm working in C# with an SQL statement below. 

```
string ConsultDiff = 
  @"SELECT AVG(ISNULL(DATEDIFF(DAY, Consult_Date, Start_Date),0)) 
     FROM patients 
    WHERE progression = 'CO' AND Plan_Type = 'New Patient' " + 
     Site + " " + Primary_Onc + " " + Type + " " + DateRange + "";

```

When there are no rows available due to the data filtering, it throws the error: 'Object cannot be cast from DBNull to other types'. I think it is having a problem with the DATEDIFF section. I want it to show a value of 0 when there is a null value. It seems to still return a null value. The code works fine when there are actual rows to pull data from.
the code is called in the following part of c#:

```
using (SqlCommand cmd3 = new SqlCommand(ConsultDiff, connection))
        {
            connection.Open();
            int countConsultDiff = Convert.ToInt32(cmd3.ExecuteScalar());
            lblConsulttoStart.Text = Convert.ToString(countConsultDiff);
            connection.Close();
        }

```