SELECT A.BUSINESS_UNIT , A.PROJECT_ID , A.EFFDT , A.LOCATION , A.LOCATION_DESCR , A.CITY , A.STATE , A.COUNTRY , A.POSTAL , B.LATITUDE , B.LONGITUDE , %NumToChar(B.LATITUDE) %Concat ' ' %Concat %NumToChar(B.LONGITUDE) FROM PS_PC_CUR_LOC_VW2 A , PS_GEOCODE_TBL B WHERE A.CITY = B.CITY AND A.STATE = B.STATE AND A.COUNTRY = B.COUNTRY AND A.POSTAL = B.POSTAL UNION SELECT A.BUSINESS_UNIT , A.PROJECT_ID , A.EFFDT , A.LOCATION , A.LOCATION_DESCR , A.CITY , A.STATE , A.COUNTRY , A.POSTAL , B.LATITUDE , B.LONGITUDE , %NumToChar(B.LATITUDE) %Concat ' ' %Concat %NumToChar(B.LONGITUDE) FROM PS_PC_CUR_LOC_VW2 A , PS_GEOCODE_TBL B WHERE A.CITY = B.CITY AND A.STATE = B.STATE AND A.COUNTRY = B.COUNTRY AND A.POSTAL <> B.POSTAL AND B.LATITUDE = ( SELECT MIN(X.LATITUDE) FROM PS_GEOCODE_TBL X WHERE X.CITY = A.CITY AND X.STATE = A.STATE AND X.COUNTRY = A.COUNTRY) AND NOT EXISTS ( SELECT 'X' FROM PS_GEOCODE_TBL C WHERE C.CITY = A.CITY AND C.STATE = A.STATE AND C.COUNTRY = A.COUNTRY AND C.POSTAL = A.POSTAL) UNION SELECT A.BUSINESS_UNIT , A.PROJECT_ID , A.EFFDT , A.LOCATION , A.LOCATION_DESCR , A.CITY , A.STATE , A.COUNTRY , A.POSTAL , B.LATITUDE , B.LONGITUDE , %NumToChar(B.LATITUDE) %Concat ' ' %Concat %NumToChar(B.LONGITUDE) FROM PS_PC_CUR_LOC_VW2 A , PS_GEOCODE_TBL B WHERE A.POSTAL = B.POSTAL AND A.STATE = B.STATE AND A.COUNTRY = B.COUNTRY AND A.CITY <> B.CITY AND A.POSTAL <> ' ' AND NOT EXISTS ( SELECT 'X' FROM PS_GEOCODE_TBL C WHERE (C.CITY = A.CITY AND C.STATE = A.STATE AND C.COUNTRY = A.COUNTRY AND C.POSTAL = A.POSTAL) OR (C.CITY = A.CITY AND C.STATE = A.STATE AND C.COUNTRY = A.COUNTRY AND C.POSTAL <> A.POSTAL))
|