select table1.* from table1 
INNER JOIN table2 on 
ltrim(rtrim(table1.productType)) = 
ltrim(rtrim(table2.productType))--应该是有空格的问题吧

解决方案 »

  1.   

    create table a (id int,productName char(3),productType varchar(10))create table b (productType varchar(10))insert into a
    select   1  ,'001','TT'
    union select 2  ,'002','ZZ'
    union select 3  ,'003','类型1'insert into b
    select 
        'TT'
    union select    '类型1'select a.* from a 
    INNER JOIN b on 
    ltrim(rtrim(a.productType)) = 
    ltrim(rtrim(b.productType))select a.* from a 
    INNER JOIN b on
    a.productType=b.productType ----------结果
    1 001 TT
    3 003 类型1
      

  2.   

    可以将productTyper的类型改为varchar(20)试试.我想应该是空格问题.
      

  3.   

    select table1.* from table1 
    INNER JOIN table2 on 
    ltrim(rtrim(table1.productType)) = 
    ltrim(rtrim(table2.productType))---试过上面的吗?行不?
      

  4.   

    先谢谢大家了!
    上面的方法都试过了,在数据也没有空格,还是不行。
    我把表放在另外的一台电脑上(win2000,sqlserver 个人版),显示的结果正确。
    真是郁闷!!!!
      

  5.   

    1、
    确认数据库中两个表的数据都是 '类型1' 而非 '类型1' (注意半角与全角的数字差别)2、
    如果productType列上建有索引,建议:
    DBCC CHECKTABLE ('table1')
    DBCC CHECKTABLE ('table2')
      

  6.   

    TO libin_ftsafe(子陌红尘) :
    两个表中的数据都是一样的,我检查过了;
    在productType列上也没有索引;
    我怀疑是不是MS SQLServer中有关设置中文的地方设置错了,请赐教,谢谢!
      

  7.   

    根据你说的根本就没什么问题,是sql server 有问题,偶尔会出现
      

  8.   

    --执行下面的两句,比较两个表中数据的编码是否一致,就可以知道原因了.select productType,cast(productType as varbinary(8000))
    from table1select productType,cast(productType as varbinary(8000))
    from table2
      

  9.   

    TO iwl :那出现这种问题该怎么解决呢?TO zjcxc(邹建):
       我用你的方法试了,table2能显示所有的数据,table1只能显示英文的,看来还是你说的编码错了,这个该怎么解决呢?请赐教,谢谢!!
      

  10.   

    解決了,原来是table1中的productType字段的默认值设置错了,本来应该是'0',写成了 0,更改过来后就没有问题了。
    谢谢大家的帮助!
    特别感谢zjcxc(邹建)兄的指点!