日期:2014-05-16 浏览次数:20511 次
declare @sql varchar(500) select @sql='select * from '+@dbName+'..tableName' --此句用于执行拼接好的SQL语句 exec(@sql) 例二: declare @sql2 varchar(max) declare @str1 varchar(20) set @str1='年龄' select @sql2='select Name as 姓名,Age as '+@str1+ case when 1<2 then ',Sex' else '' end+ ' from CBO_Person' exec(@sql2)