各位大大好 想請問一個MS SQL Table資料同步的問題
目前想把Table A的資料同步到Table B, 但Table A同時會有許多空字串跟NULL值,請問各位大大有辦法排除空字串跟NULL值再匯入Table B嗎??
附上目前實作的圖與語法
INSERT INTO [Table B] ([Dr_Key_Word]) SELECT Table A.Reason FROM Table A WHERE NOT EXISTS ( SELECT Dr_Key_Word FROM Table B WHERE Table B.Dr_Key_Word = Table A.Reason )
大大您已經寫出來了
WHERE 加上 Table A.Reason>''
或者 Table A.Reason IS NOT NULL
INSERT INTO [Table B] ([Dr_Key_Word])
SELECT Table A.Reason
FROM Table A
WHERE Table A.Reason>''
AND NOT EXISTS ( SELECT Dr_Key_Word FROM Table B WHERE Table B.Dr_Key_Word = Table A.Reason )
INSERT INTO [Table B] ([Dr_Key_Word])
SELECT Table A.Reason
FROM Table A
WHERE NOT EXISTS
(SELECT FROM Table B WHERE Table B.Dr_Key_Word = Table A.Reason AND A.Reason IS NOT NULL OR A.Reason <> '')
大概是這樣,我沒實際Try 如果有問題 應該會是 or的條件要再包括弧