INSERT INTO Verified.Routes(RouteTypeID, RouteName, [Description], OriginPlaceID, DestinationPlaceID, NationalRouteNumber, BoardRouteNumber, 
	RouteLength, RouteStatusID, OlasID, LtpsID, NeoID, ProvinceID, TimeTableDocumentID, FareScheduleDocumentID, IsChecked, IsPotentialIncorrectRouteChange, 
	IsPotentialIncorrectRouteChangeProbability)
SELECT DISTINCT fkiRouteTypeId, ISNULL(sRouteName,'UNKNOWN'), sRouteDesc, 
	ISNULL((SELECT TOP 1 PlaceID FROM Verified.Places WHERE (OlasID = OriginNode.fkiPlaceId AND OriginNode.fkiPlaceTypeId = 2) OR 
		(IntersectionOlasID = OriginNode.fkiPlaceId AND OriginNode.fkiPlaceTypeId = 4) OR 
		(RoadlinkOlasID = OriginNode.fkiPlaceId AND OriginNode.fkiPlaceTypeId = 3) OR
		(TownOlasID = OriginNode.fkiPlaceId AND OriginNode.fkiPlaceTypeId = 1) OR 
		(RankOlasID = OriginNode.fkiPlaceId AND OriginNode.fkiPlaceTypeId = 5)),(SELECT TOP 1 PlaceID FROM Verified.Places WHERE [Description] = 'UNKNOWN')), 
	ISNULL((SELECT TOP 1 PlaceID FROM Verified.Places WHERE (OlasID = DestinationNode.fkiPlaceId AND DestinationNode.fkiPlaceTypeId = 2) OR 
		(IntersectionOlasID = DestinationNode.fkiPlaceId AND DestinationNode.fkiPlaceTypeId = 4) OR 
		(RoadlinkOlasID = DestinationNode.fkiPlaceId AND DestinationNode.fkiPlaceTypeId = 3) OR
		(TownOlasID = DestinationNode.fkiPlaceId AND DestinationNode.fkiPlaceTypeId = 1) OR 
		(RankOlasID = DestinationNode.fkiPlaceId AND DestinationNode.fkiPlaceTypeId = 5)),(SELECT TOP 1 PlaceID FROM Verified.Places WHERE [Description] = 'UNKNOWN')), 
	sNationalRouteCode, sBoardRouteCode, fRouteLengthkm,
	CASE WHEN tblApprovedRoute.bActive = 0 THEN 2 ELSE 1 END,pkiApprovedRouteId,NULL,NULL,fkiProvinceId,NULL,NULL,0,0,0
FROM NDoTNTR.dbo.tblApprovedRoute INNER JOIN NDoTNTR.dbo.tblRouteNode OriginNode 
ON tblApprovedRoute.fkiGroupId = OriginNode.fkiGroupId AND OriginNode.fkiWayPointTypeId = 1 INNER JOIN NDoTNTR.dbo.tblRouteNode DestinationNode 
ON tblApprovedRoute.fkiGroupId = DestinationNode.fkiGroupId AND DestinationNode.fkiWayPointTypeId = 4
WHERE pkiApprovedRouteId NOT IN (SELECT ISNULL(OlasID,-1) FROM Verified.Routes)