用exec @temp不行??
你是在那里执行的,应该是可行的.

解决方案 »

  1.   

    declare @temp varchar(3000)
    @temp='select * from table'
    exec(@temp)
      

  2.   

    declare @temp varchar(3000)
    set @temp='select * from table'
    exec(@temp)
      

  3.   

    declare @temp varchar(3000)
    @temp='select * from table'
    exec(@temp)
      

  4.   

    试了,无法运行。说找不到这个存储过程。
    而且更难的是我还要得到其中的某个列的值。@temp='select aa from table'我想得到得出的aa列的值。是不是太难了??
      

  5.   

    应该是这样吧
    declare @temp varchar(8000)
    set @temp='select * from A表'
    exec(@temp)
      

  6.   

    @temp只是执行动态sql的语句
    访问字段还是要select 字段呀
    要做什么呢?
      

  7.   

    晕。这个就和select语句一样的用法啊!
      

  8.   

    declare @temp varchar(8000)
     select @temp=aa from A表
     select @temp
      

  9.   

    我还是没有明白。
    举个简单例子:
    在数据库中有这样一个字段的内容是:select badge form emplyee where badge='001' 这是在数据库中的。如果执行这个查询肯定是返回001的,但是怎么可以换得这个001呢???我把这段查询到@temp 中再执行:exec @temp 可是怎么传出里面的badge呢??也就是001
      

  10.   

    chinaandys(天煞孤星---风流泪、雨含笑) 
    你会错意了。@temp从数据库中读出来的内容为:select badge form emplyee where badge='001' 是一个固定的查询语句。
    exec (@temp)是可以执行但是无法反回我要的badge(001).