比如有表a,b.
更新a.total = b.price * b.number

解决方案 »

  1.   

    update a set a.total = b.price*b.number from b where b.id = a.id
      

  2.   

    如果两个表通过ID相关联,则如果是其他的,将a.ID=b.ID替换为相应字段
    UPDATE a SET a.total = b.price*b.number FROM a,b where b.ID=a.ID
      

  3.   

    ACCESS 提示
    语法错误(操作符丢失)在查询表达式'b.price*b.number from b'中我不知道是不是ACCESS的问题,我用ADO连数据库,不知用这个SQL行不行。
      

  4.   

    是不是ACCESS不支持这种句法啊。这个贴子共有220分,分别在下面几个贴子中。
    http://expert.csdn.net/Expert/topic/2446/2446844.xml?temp=.265072
    http://expert.csdn.net/Expert/topic/2446/2446848.xml?temp=.6817285
    http://expert.csdn.net/Expert/topic/2446/2446820.xml?temp=.4457666
      

  5.   

    Dim cn As New ADODB.Connection
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;data source=c:\db.mdb"
        cn.Execute "update a ,b Set total = b.price * b.Number where a.id=b.id"
        cn.Close
        Set cn = Nothing
      

  6.   

    cnn.execute "update a,b set a.total=b.price*b.number where a.id=b.id;"
    id为a,b的关联字段
      

  7.   

    access与sqlserver的update语法不一样,要注意
      

  8.   

    to yoki(小马哥)
        要是我用ADO连接的话,可以用这样的UPDATE语句吗?
      

  9.   

    我指的是连ACCESS,不是SQLSERVER
      

  10.   

    当然可以,你没有试么?
    这个就是用ado的呀Dim cn As New ADODB.Connection
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;data source=c:\db.mdb"
        cn.Execute "update a ,b Set total = b.price * b.Number where a.id=b.id"
        cn.Close
        Set cn = Nothing
      

  11.   

    我对SQL语句不熟啊,呵呵。
    两个表关联的东西能不能是一个字符型的数据。
      

  12.   

    小马哥,你好,
        能给我QQ或MSN吗?我们交个朋友吧。
    我的QQ 141633698
    我的MSN [email protected]
      

  13.   

    那能不能再多加几个运算,比如,a.total是b表中多个字段运算后的值,可以这样用吗?
    也就是说set total=后面的可以是一个表达式吗?还有,要不要FROM段?我看的例子大部分是有FROM段的。