假如由于某种原因,不能直接使用select  id, name, classid into #tmp1 from ...... 这样的语句,而必须要先把该语句放在一个字符串中,然后再调用exec(..)来执行,如果这时刚好也要把查询结果放在一个临时表中,那么相应的sql语句就要象下面这样:

1使用临时表的另外一种方式使用临时表的另外一种方式..
2使用临时表的另外一种方式declare @s varchar(2000)
3使用临时表的另外一种方式create table #tmp1(id int, name varchar(20),classid int)
4使用临时表的另外一种方式set @s='insert into #tmp1 select id, name, classid from 使用临时表的另外一种方式使用临时表的另外一种方式.'
5使用临时表的另外一种方式exec(@s)


 注意临时表一定要先定义;而且一定要使用insert into ....的形式,而不是上面的 select .... into 的形式

相关文章:

  • 2022-12-23
  • 2021-09-02
  • 2022-01-11
  • 2021-07-15
  • 2021-08-09
  • 2021-10-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-01
  • 2021-09-26
  • 2022-02-10
  • 2021-10-17
  • 2021-12-28
  • 2022-01-06
相关资源
相似解决方案