我那个gridview 的数据源不是固定的表的,  可能是很多各种各样的表, 而且需要动态的绑定..我现在只能一个事主键的字段 keyfield.然后是一个表示名称的字段..namefield 比如我从表a查的时候,用的是:select aa ,bb  form  tableA
       从表b查的时候,用的是:select  cc ,dd from  tableB我想查询出来的 cc,dd 能不能也统一成 aa,bb 能行吗. 该怎么写sql语句,或是碰到这种动态绑定的时候怎么办呢?

解决方案 »

  1.   

    select aa ,bb  form  tableA 
    union
    select  cc as aa ,dd as bb from  tableB 
      

  2.   

    select  cc as aa ,dd as bb from  tableB 这样????
      

  3.   

    明白了,谢谢大家了.我想到底是动态的添加列好,还是这样变一下字段比较好呢,呵呵...还有一个小问题.我那个表是left join 出来的. 我还想有个字段判断右边的表是否为空 也就是是tofiled是否是null的,请问该怎么写啊..select  aa as x, bb as y , isnull(tofield) as z from talbea as a left join tableb  as b  on  a.fromfield = b.tofield 也就是第三个字段返回true, false..该怎么写啊.. 
      

  4.   

    case when tofield  is null then true else false  end
      

  5.   

    select 
          aa as x, bb as y , 
            isnull(tofield,'') as z 
    from 
         talbea as a 
    left join 
          tableb  as b  
    on  a.fromfield = b.tofield ]ISNULL要有两个参数,
    上面可以用别名修改列名字