Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

como obter dados do servidor SQL ToCityId e FromCityId Bases


O abaixo resolveria seu problema:
with cte
(VoucherID,FromCity,ToCity,InDate)
as
(
select
    vh.VoucharId
,   fCity.CityName as FromCity
,   tCity.CityName as ToCity
,   InDate
from        VoucharHotel    vh
inner join  City            fCity on    vh.City = fCity.CityId
inner join  City            tCity on    vh.City = tCity.CityId 
where       vh.InDate  between '11/15/2018 12:00:00 AM' and '11/16/2018 12:00:00 AM'
)

select
*
from    cte
where   City in (1,2)

Deixe-me saber se você precisa de alterações feitas.