create table tb ( id int identity(1,1), col1 varchar(50), col2 varchar(50) )insert tb select 'a','b' union all select 'c','d' union all select 'e','f' union all select 'g','h'declare @sql varchar(1000) declare @temp varchar(50) set @temp = 'col1' --此处的列名可以是你的参数set @sql = 'select '+@temp+' into tb1 from tb'exec(@sql)select * from tb1drop table tb drop table tb1(所影响的行数为 4 行) (所影响的行数为 4 行)col1 -------------------------------------------------- a c e g(所影响的行数为 4 行)
exec('select '+diqudaima+' into :feiyong where 类别=1')commit
(
id int identity(1,1),
col1 varchar(50),
col2 varchar(50)
)insert tb
select 'a','b' union all
select 'c','d' union all
select 'e','f' union all
select 'g','h'declare @sql varchar(1000)
declare @temp varchar(50)
set @temp = 'col1' --此处的列名可以是你的参数set @sql = 'select '+@temp+' into tb1 from tb'exec(@sql)select * from tb1drop table tb
drop table tb1(所影响的行数为 4 行)
(所影响的行数为 4 行)col1
--------------------------------------------------
a
c
e
g(所影响的行数为 4 行)