2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Access SQL 追加と更新を1回でやる UPDATE RIGHT JOIN

Posted at

今までは、INSERT と UPDATEで2回SQLを実行していました。

'Partsへ更新 品番一致 受入データからの新規品番
    'strSQL = "UPDATE t_complete INNER JOIN MT_Parts ON t_complete.hinban = MT_Parts.部品名称 SET MT_Parts.最小梱包単位 = [t_complete].[suryo];"
    'db.Execute strSQL
    
    '梱包単位からMT_PartsへUPDATE
    'strSQL = "UPDATE MT_Konpo INNER JOIN MT_Parts ON MT_Konpo.[05_品番] = MT_Parts.部品名称 SET MT_Parts.最小梱包単位 = [MT_Konpo].[梱包単位];"
    'db.Execute strSQL

                    ↓

'更新と追加を1回でやる
    strSQL = "UPDATE MT_Parts AS T1 "
    strSQL = strSQL & "RIGHT JOIN tmp_Parts AS T2 ON T1.部品名称 = T2.部品名称 "
    strSQL = strSQL & "SET T1.[部品名称] = T2.部品名称, T1.[ライブラリ] = T2.[ライブラリ] , "
    strSQL = strSQL & "T1.[部品説明] = T2.部品説明 , T1.[形状コード] = T2.形状コード ,"
    strSQL = strSQL & " T1.[供給コード] = T2.供給コード ,  T1.[最小梱包単位] = T2.最小梱包単位 "
    strSQL = strSQL & " WHERE T1.[最小梱包単位] Is Null ;"

こりゃラクだわ

MySQLとかPostgresのSQLとは書き方が違うから大変。。。

2
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?