Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

come ottenere dati da SQL Server ToCityId e FromCityId Bases

Quanto segue risolverebbe il tuo 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)

Fammi sapere se hai bisogno di modifiche.