刚才没有看好题目declare @exec varchar(200) set @exec='' select @exec=@exec+','+name from syscolumns where id=object_id('table') and name<>'SAMPLING_DATETIME' order by colid select @exec='select top 50 convert(varchar(19),SAMPLING_DATETIME,121) as SAMPLING_DATETIME '+@exec+' from table ' exec (@exec)
从syscolumns表中到列名拼成SQL
set @exec=''
select @exec=@exec+','+name from syscolumns where id=object_id('table') and name<>'SAMPLING_DATETIME' order by colid
select @exec='select top 50 convert(varchar(19),SAMPLING_DATETIME,121) as SAMPLING_DATETIME '+@exec+' from table '
exec (@exec)
*
FROM T_YC_ALL_REPORT
大家可能没有明白我的意思 ,这样的
这样出现
SAMPLING_DATETIME sampling_datetime siteid 。。
2007-03-07 12:00:00 2007-03-07 12:00:00 4014 。。
2007-03-07 12:00:00 2007-03-07 12:00:00 4014 。。
这样的结果。我想要的是 SAMPLING_DATETIME siteid 。。
2007-03-07 12:00:00 4014 。。
2007-03-07 12:00:00 4014 。。这样的结果