工作需要,編寫的桌面程式連結sql server,將一些數據填入

但是會出現前一個版本有誤而需要重新填入的情況

所以這個時候就需要去判定資料庫中有沒有這筆資料.

以下範例:

if not exists (select SILK1_TOP, SILK2_TOP, SILK1_BOT, SILK2_BOT,  ADDDATE, ADDUSER, ADDTIME from Amount_DB where PART_NUMBER = 'ZN15640-01-AB')
INSERT INTO Amount_DB (SILK1_TOP, SILK2_TOP, SILK1_BOT, SILK2_BOT, ADDDATE, ADDUSER, ADDTIME) VALUES('400','500','600','700','2020-11-10','茂茂','14:13:45')  
else update Amount_DB set SILK1_TOP = '100',SILK2_TOP = '200' ,SILK1_BOT = '300',SILK2_BOT = '400' where PART_NUMBER = 'ZN15640-01-AB'

經過驗證,成功完成

此條記錄,備查.

Q.E.D.


Life’s too short to be anything but happy.