CREATE PROCEDURE  OrDerBack 
                            @WorkTableName char(30),
                            @TableName char(30),
                            @KeyName char(20),
                            @KeyNumber Char(20) ,
                            @mWorkFlowName char(20),
                            @mPerID char(20)
AS
 set nocount on
  declare @ChvSQl char(255)
  declare @TempSQL char(255)
--这里先建好临时表。
  select @ChvSQl=' select * into #temp from '+ @WorkTableName    +'where '+@KeyName+'='+@KeyNumber+' and If_Access=1 order by WorkFlowCount'
  exec(@ChvSQl)
  select * from #Temp

解决方案 »

  1.   

    临时表结构未知,
    set nocount on
    select parentsid,nowid into #temp1 from bomdetail where nowid=@ParentID
    select * from #temp1
    正确,主要临时表生存期问题
      

  2.   

    使用##Temp可解决,但如何检查##temp是否存在
      

  3.   

    你现在就像:
    if (1=2)
    {
      int i;
      i=1;
    }
    print i;
    ==========================
    你要不就用全局##
    要不就:
    int i;
    if (1=2)
    {
      i=1;
    }
    print i;相信你看得懂!
      

  4.   

    使用##Temp可解决,但如何检查##temp是否存在...........
    if object_id('tempdb..##temp') is not null
        drop table ##temp
    ...........  
      

  5.   

    CREATE PROCEDURE  OrDerBack 
                                @WorkTableName char(30),
                                @TableName char(30),
                                @KeyName char(20),
                                @KeyNumber Char(20) ,
                                @mWorkFlowName char(20),
                                @mPerID char(20)
    AS
     set nocount on
      declare @ChvSQl char(255)
      declare @TempSQL char(255)
    --这里先建好临时表。
      select @ChvSQl=' select * into #temp from '+ @WorkTableName    +'where '+@KeyName+'='+@KeyNumber+' and If_Access=1 order by WorkFlowCount
     select * from #Temp'
      exec(@ChvSQl)
    这样可以的,我现在都这样处理