/* Get the data into a temp table */SELECT * INTO #TempTableFROM YourTable/* Drop the columns that are not needed */ALTER TABLE #TempTableDROP COLUMN ColumnToDrop/* Get results and drop temp table */SELECT * FROM #TempTableDROP TABLE #TempTable
SELECT LISTAGG((column_name), ', ') WITHIN GROUP (ORDER BY column_id)INTO var_list_of_columnsFROM ALL_TAB_COLUMNSWHERE table_name = 'PUT_HERE_YOUR_TABLE'AND column_name NOT IN ('dont_want_this_column','neither_this_one','etc_column');
declare @colnames varchar(max)=''
select @colnames=@colnames+','+name from syscolumns where object_id(tablename)=id and name not in (column3,column4)
SET @colnames=RIGHT(@colnames,LEN(@colnames)-1)
# prepare column list using info from a table of choiceSET @dyn_colums = (SELECT REPLACE(GROUP_CONCAT(`COLUMN_NAME`), ',column_name_to_remove','')FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE`TABLE_SCHEMA`='database_name' AND `TABLE_NAME`='table_name');
# set sql command using prepared columnsSET @sql = CONCAT("SELECT ", @dyn_colums, " FROM table_name");
# prepare and executePREPARE statement FROM @sql;EXECUTE statement;
Dim da As New SqlDataAdapter("select * from table", cn)da.FillSchema(dt, SchemaType.Source)Dim fieldlist As String = ""For Each DC As DataColumn In DT.ColumnsIf DC.ColumnName.ToLower <> excludefield Thenfieldlist = fieldlist & DC.Columnname & ","End IfNext
SELECT 'SELECT ' || array_to_string(ARRAY(SELECT 'o' || '.' || c.column_nameFROM information_schema.columns As cWHERE table_name = 'officepark'AND c.column_name NOT IN('officeparkid', 'contractor')), ',') || ' FROM officepark As o' As sqlstmt
DECLARE @SQL NVARCHAR(MAX)SELECT @SQL = COALESCE(@SQL + ', ', ' ' ) + name from sys.columns where name not in ('colName1','colName2') and object_id = (Select id from sysobjects where name = 'tblName')SELECT @SQL = 'SELECT ' + @SQL + ' FROM ' + 'tblName'EXEC sp_executesql @SQL
DECLARE @Columns NVARCHAR(MAX)='',@SQL NVARCHAR(MAX)SELECT @Columns=CASE WHEN @Columns='' THEN name ELSE @Columns+','+name ENDFROM sys.columnsWHERE object_ID=(sELECT id FROM sysobjects WHERE name='TheTableName') and NAME!='WithoutColumnName'
SELECT @SQL='SELECT '+@Columns+' FROM dbo.TheTableName'EXEC sp_execute @SQL