title: SQL HAVING BETWEEN a date range
body: <p>I am trying to retrieve the count of records between a certain date range that is specific to the users min date and max date in another table.</p>
  
  <p>This is what I have so far, however it is excluding at least 13 records that I know of. Can you tell if there is an error in my logic?</p>
  
  <p>Thanks in advance for any input you have! </p>
  
  <pre><code>SELECT   rtam.dbo.wfm_process_instance.user_id AS user_id,
           MIN(rtam.dbo.wfm_process_instance.LOCAL_USER_START_TIME) AS Min_Date,
           MAX(rtam.dbo.wfm_process_instance.LOCAL_USER_START_TIME) AS Max_Date,
           0 AS IVR_Calls,
           COUNT(*) AS Total_Calls
  FROM     rtam.dbo.WFM_PROCESS_INSTANCE
           LEFT OUTER JOIN
           rtam.dbo.WFM_PROCESS_type
           ON rtam.dbo.wfm_process_instance.PROCESS_TYPE_INDX = rtam.dbo.wfm_process_type.INDX
  WHERE    rtam.dbo.wfm_process_type.DISPLAY_NAME = 'DTV Inbound2'
           AND EXISTS (SELECT   rtam.dbo.gnr_Tbl_72_type.CTRL_USER_ID,
                                CONVERT (VARCHAR (10), MIN(rtam.dbo.gnr_tbl_72_type.LOCAL_COL_113), 101) AS min_date,
                                CONVERT (VARCHAR (10), MAX(rtam.dbo.gnr_tbl_72_type.local_col_113), 101) AS max_date
                       FROM     rtam.dbo.GNR_TBL_72_TYPE
                       WHERE    rtam.dbo.GNR_TBL_72_TYPE.CTRL_USER_ID = rtam.dbo.wfm_process_instance.USER_ID
                       GROUP BY rtam.dbo.GNR_TBL_72_TYPE.CTRL_USER_ID
                       HAVING   rtam.dbo.wfm_process_instance.LOCAL_USER_START_TIME BETWEEN CONVERT (VARCHAR (10), MIN(rtam.dbo.gnr_tbl_72_type.LOCAL_COL_113), 101) AND CONVERT (VARCHAR (10), MAX(rtam.dbo.gnr_tbl_72_type.LOCAL_COL_113), 101))
  GROUP BY rtam.dbo.wfm_process_instance.USER_ID
  ORDER BY rtam.dbo.wfm_process_instance.USER_ID;
  </code></pre>