declare @str varchar(1000)
set @str=''
select @str=@str+','+a.[name] from syscolumns a,sysobjects b where a.id=b.id and b.id=object_id('表名') and a.name not in('列名','列名')--这里写不要的列名
set @str=stuff(@str,1,1,'')
exec('select '+@str+' from 表名')
----------------------------------------------------------------------------------------------------------------------------------------------
e.g:
declare @str varchar(1000)
set @str=''select @str=@str+','+a.[name] from syscolumns a,sysobjects b where a.id=b.id and b.id=object_id('[wr2].[BudgetEstimateRequest]') and a.name not in('ContactBy','Url',
'CustomHeadings',
'GeoType',
'Comments',
'BusinessAddress',
'Radius',
'Latitude',
'Longitude',
'GeoModifier',
'ExpirationDate',
'ResultLocation',
'SalesContactEmail',
'SalesAgentID',
'SelfEstimated',
'AssignedAnalystID',
'RejectedEstimateID',
'RejectedEstimateText',
'NewHeadingDescription',
'EvaluationRange',
'resultNote',
'LandingPageEvaluationStatus',
'CompetitivePPCStatus',
'PromotionID',
'AdvertiserID',
'IsPreSale',
'MaxCPC',
'BudgetAmount'
)
set @str=stuff(@str,1,1,'')
exec('select '+@str+' from [wr2].[BudgetEstimateRequest] WHERE RequestID > 40520 and DMSAnnualBudget is not null')