The following is my query
Select vehicleID from trip where (StartingDate between + convert(varchar(10), @StartDate,111) + and + convert(varchar(10), @EndDate,111)+ )
or (enddate between + convert(varchar(10), @StartDate,111) + and + convert(varchar(10), @EndDate,111)+ )
or(StartingDate <= @StartDate and enddate >= @EndDate)
UNION
Select vehicleID from VehicleMaintenance where (FromDate between + convert(varchar(10), @StartDate,111) + and + convert(varchar(10), @EndDate,111)+ )
or (todate between + convert(varchar(10), @StartDate,111) + and + convert(varchar(10), @EndDate,111)+ )
or (FromDate <= @StartDate and todate >= @EndDate)
) as vehicle
how to select distinct vehicleId from the above query result....