sql >> Base de Datos >  >> RDS >> Sqlserver

cómo obtener datos del servidor SQL ToCityId y FromCityId Bases

¿Podría lo siguiente resolver su 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)

Avíseme si necesita cambios.