如果Publisher_ID=Publisher_Name
可以这样:
update T_BookInfo  set Publisher_ID=a.Publisher_ID from T_Book_Publisher a
where Publisher_ID=a.Publisher_Name如果不相等,请列出这两个表之间的联系

解决方案 »

  1.   

    把T_BookInfo表中的Publisher_ID转换成T_Book_Publisher表中的Publisher_Name表的ID请解释上句
      

  2.   

    有些不懂
    现在我想把T_BookInfo表中的Publisher_ID转换成T_Book_Publisher表中的Publisher_Name表的ID??是不是你想把T_BookInfo.Publisher_ID换成T_Book_Publisher.Publisher_Name还是其他的?????
    例如
    T_BookInfo表中如下信息    T_Book_Publisher表中如下信息    
    Publisher_ID               Publisher_ID       Publisher_Name
    A出版社信息                     PA               A出版社名字   
    B出版社信息                     PB               B出版社名字   
    C出版社信息                     PC               C出版社名字   
    D出版社信息                     PD               D出版社名字   那么你想得到什么结果呢??????
      

  3.   


    --先把t_bookinfo中publisher_id在t_book_publisher的字段publisher_name中没有的设置为0,
    --既在t_book_publisher的publisher_name中没有t_bookinfo中publisher_id的内容。
    update t_bookinfo  set publisher_id=0 
    where publisher_id not in (select publisher_name from t_book_publisher)
    go
    --(上面的可以不要)declare @p_id varchar(50)
    declare @p_name varchar(50)DECLARE myCursor CURSOR FOR 
    SELECT publisher_id,publisher_name
    FROM t_book_publisher
    OPEN myCursor
    FETCH NEXT FROM myCursor INTO @p_id,@p_name
    WHILE @@FETCH_STATUS = 0
    begin
    update t_bookinfo  set publisher_id=@p_id where publisher_id=@p_name
    FETCH NEXT FROM myCursor INTO @p_id,@p_name
    end
    CLOSE myCursor
    DEALLOCATE myCursor
    GO
    --最后修改表字段类型与t_book_publisher的publisher_id的字段类型相同
    alter table t_bookinfo alter column publisher_id int
    go
      

  4.   

    楼主已在另一帖中说明是:office2003,
    我想是在access中
      

  5.   

    我把数据库导到sql里面去了,运行成功,谢谢大家了,今天太迟了,明天我好好研究一下这代码