views:

19

answers:

1

Hi guys,

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....

+1  A: 

Note that UNION will remove duplicates (whereas UNION ALL will not), so you should already have unique vehicle ID's

Mitch Wheat