根据另一列更新一列中的值

时间:2017-02-15 10:36:25

标签: sql-server tsql

我希望使用表格USER_FNM中的值更新临时表@Users中的BAUSER

@Users

DECLARE @USERS TABLE
(
  USER_KEY INT,
  USER_FNM VARCHAR(50),
  USER_LNM VARCHAR(50),
  USDE_HSU DECIMAL(8,2),
  [110000003] DECIMAL(8,2),
[120000002] DECIMAL(8,2),
[120000003] DECIMAL(8,2)
)

我已经尝试过的是:

update @USERS 
set USER_FNM = (select top(1) user_fnm from bauser where bauser.user_key = USER_KEY)

但是这总是从BAUSER表返回第一个值。如何迭代@Users的每一行并更改USER_FNM

1 个答案:

答案 0 :(得分:1)

SQL Server支持更新语句中的联接 假设user_key在表bauser中是唯一的,您可以简单地执行此操作:

$ sudo adb version
Android Debug Bridge version 1.0.36
Revision 0e9850346394-android

$ sudo adb devices -l
List of devices attached
52036e4ff4229373       device usb:1-1 product:gtaxlltexx model:SM_T585 device:gtaxllte

$ sudo adb install system-service/app/system-service-release.apk 
[100%] /data/local/tmp/system-service-release.apk
    pkg: /data/local/tmp/system-service-release.apk
Failure [INSTALL_FAILED_SHARED_USER_INCOMPATIBLE]
$