想要取一个表第N列的内容,怎么写啊???
col_name(OBJECT_ID( 'base '),1)为表base的第一列的列名,我想问一下取base第一列的内容,怎么写啊?
------解决方案--------------------用动态SQL
------解决方案-------------------- declare @colname varchar(100)
select @colname=col_name(OBJECT_ID( 'base '),1)
exec ( 'select '+@colname+ ' from base ')
------解决方案--------------------declare @var varchar(1000)
set @var = 'select '+ CONVERT( varchar(1000),col_name(OBJECT_ID( 'pp..ww '),1)) + ' from ww '
exec (@var)
------解决方案--------------------declare @var varchar(1000)
set @var = 'select '+ CONVERT( varchar(1000),col_name(OBJECT_ID( 'base '),1)) + ' from base '
exec (@var)
------解决方案--------------------up