Question: What is wrong in this error ?  

> 
> alter table INFO add constraint chk\_app check
>  (CASE WHEN app IS NULL THEN app = 'A');   
> 
> 
> 
> 

If its because *app = 'A'* I am calling it twice then how to have a check constraint to check if app is null then it should have value A

Answer: 
@FreefallGeek, 

What do you mean by you can't filter AppointmentDate if you remove it from SELECT? Report Builder allows you do dataset filtering based on the user assigned parameter in run time with query like this,

```
SELECT DISTINCT PaientID, InsuranceCarrier 
FROM Encounters
WHERE 
  AppointmentDate >= @beginningofdaterange
  AND AppointmentDate <= @endofdaterange

```

With @beginningofdaterange and @endofdaterange as your report parameter. This should work unless you need to do additional filtering that require to return AppointmentDate as result.

If you really need to return the Appointment date as result or for additional filtering, then the next question is what should be the AppointmentDate when there are multiple visit with same patient and insurance carrier? The first visit or the last visit within the date range? If that is the case, you could use group by like this for first visit,

```
SELECT Min(AppointmentDate) AS FirstAppointmentDate, PaientID, InsuranceCarrier 
FROM Encounters
WHERE 
  AppointmentDate >= @beginningofdaterange
  AND AppointmentDate <= @endofdaterange
GROUP BY PaientID, InsuranceCarrier
ORDER BY AppointmentDate

```

However, from your description, it appears that you only need the distinct patient and insurance carrier with the capability to filter the date. If that understanding is correct, you could just filter the appointment with user input parameter in the WHERE clause without the SELECT.
In this particular case, I would take into account all visits per the entire day. And instead of displaying multiple encounters per patient per day, I would go to display for the report as AppointmentDate only the day part of the AppointmentDate itself. As the filtering might not need the exact moment of the visit, but only the fact that it took place. The resulting set would be then filtered by the report.

Your particular select would look like the following:

```
-- small modification (take encounters by entire day):
SELECT DISTINCT
  CAST(e.AppointmentDate as Date) as AppointmentDateDay, -- the day of the visit 
  e.PatientID,
  e.InsuranceCarrier,
  COUNT(e.Id) as CntVisits -- display them if you'd like
FROM Encounters as e
WHERE AppointmentDate >= '20130624 10:00:00'
AND AppointmentDate <= '20130625 18:00:00'
GROUP BY PatientID, InsuranceCarrier, CAST(e.AppointmentDate as Date)
ORDER BY PatientId;

```

Example [Fiddle](http://sqlfiddle.com/#!3/893d6/2) - see both result sets.

If you really need to show the entire AppointmentDate to the user, I admit I don't have an idea now.