Excerpt from:http://blog.163.com/[email protected]/blog/static/164628503201231925214824/
query all fields except the specified field
declare @name varchar (declare @sql varchar) SET @sql = ' SELECT ' Declare C11 CURSOR for select name from Sysco Lumns where id= (select Max (id) from sysobjects where xtype= ' u ' and name= ' table name ') and name <> ' except Fields ' OPEN C11 FETCH N EXT from C11 to @name IF @ @FETCH_STATUS <> 0 BEGIN deallocate C11 RETURN END while (@ @FETC H_status = 0) BEGIN SET @[email protected][email protected]+ ', ' FETCH NEXT from C11 into @name END deallocate C11 Set @sql =substring (@sql, 1,len (@sql)-1) + ' from table name ' EXEC (@sql)
--Query all fields in a tableselect name from syscolumns where id= (select Max (id) from sysobjects where xtype= ' u ' and name= ' table name ')
SQL query, excluding specified fields