How to select all the columns of a table except one column?

前端 未结 13 2438
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 05:43

How to select all the columns of a table except one column?

I have nearly 259 columns I cant mention 258 columns in SELECT statement.

Is there

13条回答
  •  甜味超标
    2020-12-14 05:54

    Try the following query:

    DECLARE @Temp NVARCHAR(MAX); 
    DECLARE @SQL NVARCHAR(MAX);
    
    SET @Temp = '';
    SELECT @Temp = @Temp + COLUMN_NAME + ', ' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='Person' AND COLUMN_NAME NOT IN ('Id')  
    
    SET @SQL = 'SELECT ' + SUBSTRING(@Temp, 0, LEN(@Temp)) +' FROM [Person]';
    EXECUTE SP_EXECUTESQL @SQL;
    

提交回复
热议问题