简体   繁体   中英

Is there another solution for SQL server

I have a small problem :

SELECT *
FROM  ZGA_DASHBOARD_FINAL
full outer join A_SGA_Name_ID_Final ON cast(REFERENCE_KEY1 as integer) =A_SGA_Name_ID_Final.[PERSONID_EXT]
WHERE ISNUMERIC(REFERENCE_KEY1) = 1 

For my output I have this error : Conversion failed when converting the varchar value 'CORRECT' to data type int.

and when I change full outer join by Inner join it works Someone had the same problem.. Thanks in advance

You can use a CTE to first limit the records where the ISNUMERIC returns true:

; WITH NumericReference
AS (
    SELECT *
    FROM  ZGA_DASHBOARD_FINAL
    WHERE ISNUMERIC(REFERENCE_KEY1) = 1
    )
    SELECT *
    FROM  [NumericReference] nr
    FULL OUTER JOIN A_SGA_Name_ID_Final af 
        ON CAST(nr.REFERENCE_KEY1 AS INTEGER) = af.[PERSONID_EXT]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM