两个表test1,test2
test1:
编号 名称 厂家
1 a
2 b
3 c
4 d
5 e
6 f
test2:
编号 厂家
2 广东
5 厦门
6 深圳
我想把test2的编号和test1编号相同的厂家名称 加到test1得厂家中:
update test1 set test1.厂家=test2.厂家 from test2,test1
where test1.编号=test2.编号
哪里错了?

解决方案 »

  1.   


    update test1 set 厂家=test2.厂家 from test2 t
    where test1.编号=t.编号 
      

  2.   

    update test1 set 厂家=test2.厂家 
    from test2,test1 
    where test1.编号=test2.编号 
      

  3.   

    update 
      test1 
    set 
      厂家=test2.厂家 
    from 
      test2,test1 
    where 
      test1.编号=test2.编号 
      

  4.   

    update a set 厂家=b.厂家 from test2 b,test1 a
    where a.编号=b.编号 
      

  5.   


    update test1 set test1.厂家=test2.厂家 from test2,test1 
    where test1.编号=test2.编号 对的呀
      

  6.   

    update 
      a 
    set 
      a.厂家=b.厂家 
    from 
      test2 b,
      test1 a
    where 
      a.编号=b.编号 a
      

  7.   

    create table test1(编号 int, 名称 varchar(10), 厂家 nvarchar(10)) 
    insert test1 select 1 ,'a',null 
    insert test1 select 2 ,'b' ,null
    insert test1 select 3 ,'c' ,null
    insert test1 select 4 ,'d' ,null
    insert test1 select 5 ,'e' ,null
    insert test1 select 6, 'f' ,null
    create table test2(编号 int, 厂家 nvarchar(10))
    insert test2 select 2, N'广东' 
    insert test2 select 5, N'厦门' 
    insert test2 select 6, N'深圳' 
    update test1 set test1.厂家=test2.厂家 from test2,test1 
    where test1.编号=test2.编号 
    SELECT * FROM TEST1
    DROP TABLE TEST1,TEST2
    /*
    编号          名称         厂家
    ----------- ---------- ----------
    1           a          NULL
    2           b          广东
    3           c          NULL
    4           d          NULL
    5           e          厦门
    6           f          深圳(6 個資料列受到影響)
    */
      

  8.   


    create TABLE test1(编号 INT,名称 VARCHAR(6),厂家  VARCHAR(6))
    INSERT INTO test1 select
    1, 'a','' union all select 
    2, 'b','' union all select  
    3, 'c','' union all select  
    4, 'd','' union all select  
    5, 'e','' union all select  
    6, 'f','' 
     
    --> 生成测试数据: @tb3
    create TABLE test2(编号 INT,厂家 VARCHAR(12))
    INSERT INTO test2 select
    2, '广东'  union all select 
    5, '厦门'  union all select 
    6, '深圳'update test1 set 厂家=t.厂家 from test2 t
    where test1.编号=t.编号 
    select * from test1
    drop table test1
    drop table test2
    编号          名称     厂家
    ----------- ------ ------
    1           a      
    2           b      广东
    3           c      
    4           d      
    5           e      厦门
    6           f      深圳(6 行受影响)
      

  9.   

    可我在access里面运行弹出窗口,“语法错误(操作符丢失)在查询表达式‘test2.厂家 from test1’中”高手再帮看一下
      

  10.   

    可我在access里面运行弹出窗口,“语法错误(操作符丢失)在查询表达式‘test2.厂家 from test1’中”高手再帮看一下
      

  11.   

    可我在access里面运行弹出窗口,“语法错误(操作符丢失)在查询表达式‘test2.厂家 from test1’中”高手再帮看一下