代码之家  ›  专栏  ›  技术社区  ›  Rey

为SQL Server转换MS Access查询

  •  0
  • Rey  · 技术社区  · 6 年前

    这是我需要更新以在SQL Server中使用的查询:

      UPDATE
        dbo.TPR00100
      INNER JOIN (
        dbo.UPR10302
        LEFT JOIN dbo.B3980280 ON dbo.TPR10302.COMPTRNM = dbo.B3980280.COMPTRNM
      ) ON dbo.TPR00100.STAFFID = dbo.TPR10302.STAFFID
      SET
        dbo.B3980280.COMPTRNM = dbo.TPR10302.comptrnm,
        dbo.B3980280.BI_LOC_ID = dbo.TPR00100.locatnid
      WHERE
        (((dbo.B3980280.COMPTRNM) Is Null))
    

    对于此查询,在SQL Server事务中需要以不同方式处理的关键方面是什么?

    1 回复  |  直到 6 年前
        1
  •  1
  •   GMB    6 年前

    如果您觉得使用可更新的CTE很方便:

    with cte as (
        select
            b39.comptrnm b39_comptrnm
            b39.bssi_loc_id b39_bssi_loc_id,
            tpr.comptrnm tpr_comptrnm,
            tpr.locatnid tpr_locatnid
        from dbo.tpr00100 tpr
        inner join dbo.upr10302 upr on tpr.staffid = upr.staffid
        inner join dbo.b3980280 b39 on tpr.comptrnm = b39.comptrnm
        where b39_comptrnm is null
    )
    update cte 
    set b39_comptrnm = tpr_comptrnm, b39_bssi_loc_id = tpr_locatnid
    

    left join