sql 有没有一个简化写法,使得 select (3~最后一列) from table 语句中,不用把 3~最后一列 的列名都写出来?
------解决方案--------------------
declare @columns varchar(50),@sql varchar(max)
set @columns=''
select @columns=@columns + ',' + a.name
from sys.columns a
inner join sys.tables b
on a.object_id=b.object_id
where b.name='TableName'
and a.column_id>2
set @columns=STUFF(@columns, 1, 1, '')
set @sql='select '+@columns+' from TableName'
select @sql
exec(@sql)