Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用另一个表上同一行的元素更新表的值_Sql_Sql Server_Sql Update_Ssms - Fatal编程技术网

Sql 使用另一个表上同一行的元素更新表的值

Sql 使用另一个表上同一行的元素更新表的值,sql,sql-server,sql-update,ssms,Sql,Sql Server,Sql Update,Ssms,我有一个包含多行的表a和一个只返回一行的表B的函数。我需要用B中函数返回的标准值更新A.Other和A.ID的每个值,因此从: ---------- TABLE A --------- ------------ TABLE B ------------ id Name ID Other Def_Other Def_Province Def_ID 1 x 1 asqas hello PD

我有一个包含多行的表a和一个只返回一行的表B的函数。我需要用B中函数返回的标准值更新A.Other和A.ID的每个值,因此从:

---------- TABLE A ---------      ------------ TABLE B ------------
id     Name   ID   Other        Def_Other   Def_Province   Def_ID 
1        x    1    asqas         hello        PD            0
2        y    10   asd
3        Z    12   adf      
表A应改为:

---------- TABLE A --------- 
id     Name   ID   Other     
1        x     0   hello    
2        y     0   hello
3        Z     0   hello
我已经试过了

update dbo.Table_A 
set Other = select top 1 name FROM dbo.generate_table_b(1)
但我做不到。 是否可以在不为每列\类型声明变量的情况下执行此操作?我必须编辑许多不同类型的字段。 提前感谢。

您可以使用应用程序:

我想你想要:

update a
    set Other = b.name,
        id = b.Def_ID 
    from dbo.Table_A a cross join
         dbo.generate_table_b(1) b;
update a
    set Other = b.name,
        id = b.Def_ID 
    from dbo.Table_A a cross join
         dbo.generate_table_b(1) b;