开发者

Union in SQL Server 2005

开发者 https://www.devze.com 2022-12-17 10:39 出处:网络
The following is my query Select vehicleID from trip where (StartingDate between \'\'+ convert(varchar(10), @StartDate,111) +\'\' and \'\'+ convert(varchar(10), @EndDate,111)+\'\')

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) +'' a开发者_JAVA百科nd ''+ 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....


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号