declare @AAAAA varchar(1000)
declare @s varchar(8000)
set @s = 'select A,B,C,(select D from TABLE '+@AAAAA+') from ....'
set @@AAAAA = 'where 1=1'
exec (@s)

解决方案 »

  1.   

    declare @aaaa=' where id=1'
    exec('slelect A,B,C,(select D from TABLE '+@AAAAA+') from ....')
      

  2.   

    http://expert.csdn.net/Expert/topic/2364/2364046.xml?temp=.829693
    [交流]动态SQL语句
      

  3.   

    变量不能直接用于from 语句,改用exec动态执行就可以了.declare @tb sysname
    set @tb='AAAAA'exec('slelect A,B,C,(select D from '+@tb+') from ....')
      

  4.   

    一般用执行字符串的方式即可,既先根据各个变量组合成一个具体的执行字符串,然后执行这个字符串就可以了!一般用EXEC就可以,建议用sp_executesql,具体可一看帮助文件!