I am running a CREATE TABLE TBL AS SELECT statement as below. I want to write a CASE STATEMENT that will compare values from column X.PRESC_ID to values from column Y.PRSC_NPI and if there is match, it should INSERT to TBL.PRESC_ID, and for all the X.PRESC_ID that do not match with any value in Y.PRSC_NPI should be INSERTED to TBL.PRSC_NPI_N
CREATE TABLE TBL (
Col1,
Col2,
PRESC_ID,
PRSC_NPI_N,
AS
(
SELECT
Col1,
Col2,
PRESC_ID,
PRSC_NPI_N,
FROM TBL2 X
JOIN
(SELECT CLAIM_ID,PRSC_NPI FROM TBL3) Y
ON Y.CLAIM_ID = Y.Col1
I have tried the one below but it is not working
CASE
WHEN X.PRESC_ID = Y.PRSC_NPI THEN TBL.PRESC_ID
ELSE TBL.PRSC_NPI_N
END