none
How to select * [except column] from tableName? RRS feed

  • 问题

  • Now I have a table T which I only know it has a column named flag,and I want to get all data of T exclude the flag column.

    like:

    create table T
    (
        firstColumn varchar(20),
        secondColumn varchar(20),
        flag smallint
    )

    But what I know is just the table T has a column named flag.

    My expected result is : select firstColumn,secondColumn from T;

    How can I accomplish it?

    Thanks for attention!


    shutear

    2012年12月15日 16:04

答案

  • 这里有一个例子可以参考下 利用syscolumn

    USE [pratice]
    GO
    
    create view vtest
    as
    select 1 as a,2 as b ,3 as c
    go
     
     SELECT * FROM vtest
     
     
    declare @s varchar(1000)
     
    select @s = isnull(@s+',','') +name
    from syscolumns 
    where id = OBJECT_ID('vtest') and name <> 'a'
     
    exec('select '+ @s + ' from vtest')
     
    drop view vtest


    给我写信: QQ我:点击这里给我发消息

    • 已标记为答案 shutear 2012年12月16日 4:59
    2012年12月15日 16:32