C
china_peng
Unregistered / Unconfirmed
GUEST, unregistred user!
sql语法中表名、字段都为变量的,在[red]sql server[/red]中取@chr_03有没有比这更简便的写法,能否用一句话搞定!
DECLARE @chr_01 varchar(20),@chr_02 varchar(20) ,@chr_03 varchar(20),@sqlstr varchar(7000)
select @chr_01='mi01'
select @chr_02='maumi'
create table #tab(aaa varchar(20))
select @sqlstr='insert into #tab(aaa) select '+@chr_01+' from '+@chr_02+' where mi02=''1'' '
--[red]我的程序中只考虑 select mi01 from maumi where mi02='1' 返回一笔记录![/red]
print @sqlstr
exec(@sqlstr)
select @chr_03=aaa from #tab
print @chr_03
drop table #tab
DECLARE @chr_01 varchar(20),@chr_02 varchar(20) ,@chr_03 varchar(20),@sqlstr varchar(7000)
select @chr_01='mi01'
select @chr_02='maumi'
create table #tab(aaa varchar(20))
select @sqlstr='insert into #tab(aaa) select '+@chr_01+' from '+@chr_02+' where mi02=''1'' '
--[red]我的程序中只考虑 select mi01 from maumi where mi02='1' 返回一笔记录![/red]
print @sqlstr
exec(@sqlstr)
select @chr_03=aaa from #tab
print @chr_03
drop table #tab