A表的A1字段数据类型varchar(50),有数据是00500,B表的B1字段也是varchar(50),当有个条件后,A表查出有数据,B表没数据,但A union B 后 A1(B1)字段 数据变成了 500,求解?是不是变成整形了?

解决方案 »

  1.   

    这样吧,你执行
    select A1 from A
    Union 
    select B1 from B
    看看会不会变
      

  2.   

    应该是字段的类型不一致,你在检查下
    Declare @A varchar(10)
    Declare @B varchar(10)
    set @A ='0500'
    set @B =''
    select @A
    union 
    Select @B
      

  3.   

    你查询时,使用cast.select cast(a1 as varchar(50)) from A
    union all
    select cast(b1 as varchar(50)) from b
      

  4.   


    declare @a table(id int,acol varchar(50))
    insert into @a
    select 1,'00500' union all
    select 2,'022'declare @b table(id int,bcol varchar(50))
    insert into @b
    select 3,'400'select * from @a
    select * from @b
    select * from @a where id=1
    select * from @b where id=3
    select * from @a union all
    select * from @b
    --============================
    --以上语句结果0都没有丢。
    --============================