是否可以选择除一列之外的所有列?
这是所有列名称:ID,名称,地址,年龄
SELECT id, name, address from TBLUser
我不想使用此select语句,因为我的表的列数彼此不同。
declare @cols varchar(max), @sql varchar(max) SELECT @cols = STUFF ( ( SELECT DISTINCT ‘], [‘ + name FROM sys.columns where object_id = ( select top 1 object_id from sys.objects where name = ‘TBLUser’ ) and name not in (‘age’) FOR XML PATH(‘’) ), 1, 2, ‘’ ) + ‘]’ select @sql = ‘select ‘ + @cols + ‘ from TBLUser’ exec (@sql)