表中存在有如下一些列 如:CH部门  CH单位 CH问题.......... 姓名 年龄
现在 如果只需要去带‘CH’得列名 取得后同时去掉‘CH’
如‘CH部门’ 只显示‘部门’
并且存在多个 上述类似得表 
请问要取得 类似‘部门这样得列’ SQL语句如何实现?

解决方案 »

  1.   

    select right('CH部门', len('CH部门')-2)
      

  2.   

    select right(CH部门,len(CH部门)-2) as 部门,
           right(CH单位,len(CH单位)-2) as 单位,
           right(CH问题,len(CH问题)_2) as 问题
           .......... 
           姓名,
           年龄
    from tb可是这个意思?
    最好你给出字段,数据和想要的结果.
    不然不好搞.
      

  3.   

    因为带'CH'的有很多列, 并且每次取得表也不同 ,当然列也不同 但都需要取得带'CH'的列   
    ,是不是应该有别的办法
      

  4.   

    取数据库所有带CH的字段名
    select b.name
    from  sysobjects  a , syscolumns b 
    where  a.id=b.id and  a.type='U'  and  b.name like '%CH%'
      

  5.   


    取数据库所有带CH的字段名同时去掉‘CH’
    select right(b.name,len(b.name)-2) as name
    from  sysobjects  a , syscolumns b 
    where  a.id=b.id and  a.type='U'  and  b.name like '%CH%'
      

  6.   

    如果还要显示表名,那么
    select a.name as tbname,right(b.name,len(b.name)-2) as colname
    from  sysobjects  a , syscolumns b 
    where  a.id=b.id and  a.type='U'  and  b.name like 'CH%'
      

  7.   

    用动态SQL来做吧
    create procedure select_noch(@tablename varchar(100))
    as 
    declare @sql varchar(8000)
    set @sql='select '
    select @sql=@sql+a.name+(case when a.name like 'CH%' then ' '+right(a.name,len
      (a.name)-2) else '' end)+',' from  syscolumns a inner join sysobjects b on 
      a.id=b.id where  b.type='U'  and  b.name =@tablename order by colid
    set @sql=left(@sql,len(@sql)-1)+' from '+@tablename
    exec(@sql)