declare @tablename
set @tablename = '...'
exec('select * from '+@tablename +' where ... ')

解决方案 »

  1.   

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

  2.   

    declare @tablename
    set @tablename = '...'
    exec('select * from '+@tablename +' where ... ')
    楼上的,你这个是放在存储过程里面吗???
    我没用过这东西呀。。
      

  3.   

    就是动态sql的使用
    declare @tablename
    set @tablename = '...'
    exec('select * from '+@tablename +' where ... ')
      

  4.   

    string AllSql="declare @tablename @AppID @ContentID";
    string AllSql=AllSql+"set @tablename = 'Select TableName from Workflow_App where AppID=@AppID and ContengID=@ContentID'";
    AllSql="Select WhoDo.CB,App.AppID,App.AppName,Content.RecordID,Content.CurStepID,Content.Subject,Content.ContentID,Content.AppID,WhoDo.LastDoneTime,WhoDo.AppID from Workflow_App App,"+XTableName+" Content,Workflow_Whodo WhoDo where App.AppID=WhoDo.AppID and WhoDo.ContentID=Content.ContentID and UserID="+Session["ID"]+" order by WhoDo.LastDoneTime DESC";我怎么得到@AppID 和@ContentID.....????