求一条SQL语句,要求把A表某个字段的值,赋成这A表的ID=31的这条记录的这个字段的值

解决方案 »

  1.   

    select A.a where A.ID=31 into @tmp;
    update A set A.a = @tmp;
      

  2.   

    update A set col = (select col from A where id = 31 limit 1)
      

  3.   

    update A set col = (select col from A where id = 31 limit 1)这一种在MYSQL中是不好用的,在SQL2000中没有事。
      

  4.   

    create proc upAUpdateFieldValeByID
    (
       @FieldName varchar(255),
       @ID        varchar(255)
    )
    as
    begin
       exec('update A set ' + @FieldName + ' = (select ' + @FieldName ' from A where id = ' + @ID + ')')
    end