select
    'VEHICLE_REGISTRATION' as entity_type,
    cast(v.ID as varchar(128)) as source_entity_id,
    concat(coalesce(n.AlphaCode, ''), ':', v.VRN) as source_external_key,
    concat(coalesce(n.AlphaCode, ''), ':', v.VRN) as display_name,
    cast(case when v.ValidTo is null or v.ValidTo > getutcdate() then 1 else 0 end as bit) as active,
    cast(null as datetime) as valid_from,
    cast(null as datetime) as valid_to,
    cast(null as datetime) as source_updated_at,
    v.ID as vehicle_registration_id,
    cast(v.ID_VehicleIdentification as varchar(128)) as vehicle_identification_id,
    n.AlphaCode as registration_nation,
    v.VRN as registration_number,
    v.VrnNormalized as registration_number_normalized,
    v.ID_FileLog as file_log_id,
    v.LastDriver_ID as last_driver_id,
    v.LastDriverTime as last_driver_time
from dbo.Vehicle v
left join dbo.Nation n on n.ID = v.ID_Nation
where v.VRN is not null
