Create proc TT_Select
@MyParam varchar(50)
as
  declare @cmd varchar(255)
  @cmd='SELECT  [Name], [CastType], [ProgramType], [Parent] 
  FROM [sms].[dbo].[T_Program]
where  [Name] like '+@@MyParam+'% into #MyTempTable'
  exec @cmd
  return
goExec TT_Select '节目'
  

解决方案 »

  1.   

    xzou(缺齿小狼):
    好像不行
    Server: Msg 203, Level 16, State 2, Procedure TT_Select, Line 8
    The name 'SELECT  [Name], [CastType], [ProgramType], [Parent] 
      FROM [sms].[dbo].[T_Program]
    where  [Name] like 节目% into #MyTempTable' is not a valid identifier.
      

  2.   

    回复人: xzou(缺齿小狼) (2001-9-10 16:10:43)  得0分 
    Create proc TT_Select
    @MyParam varchar(50)
    as
      declare @cmd varchar(255)
      @cmd="SELECT  [Name], [CastType], [ProgramType], [Parent] 
      FROM [sms].[dbo].[T_Program]
    where  [Name] like '"+@@MyParam+"%' into #MyTempTable"
      exec @cmd
      return
    goExec TT_Select '节目'
       
      

  3.   

    这样可以吗?
    Create proc TT_Select
    @MyParam varchar(50)
    as
      DELETE FROM #MyTempTable;  INSERT INTO #MyTempTable
      SELECT  [Name], [CastType], [ProgramType], [Parent] 
      FROM [sms].[dbo].[T_Program]
    where  [Name] like @MyParam+'%'
    GOExec TT_Select '节目'
      
      

  4.   

    另外一種方式:
    在存儲過程之外,先建好temp table.然後再執行你的SP.
     
    INSERT INTO #myTempTable EXEC TT_Select '節目'
      

  5.   

    N_chow(一劍飄香):
        我用的是sql server ,好像不支持这种语法
    INSERT INTO #myTempTable EXEC TT_Select '節目'
      

  6.   

    可以呀。
    你先建好一個Temp table.
    然後再 
    INSERT INTO #myTempTable Exec TT_Select '節目'
    前提是先建好Temp table.
      

  7.   

    是这样的吗?
    DECLARE @RC int
    DECLARE @MyParam varchar(50)
    set @MyParam='节目'
    drop table #tmp
    select * into #tmp from [sms].[dbo].[T_Program] where 1=2
    insert into #tmp EXEC [sms].[dbo].[TT_Select] @MyParamselect * from #tmp
    -------------------------
    但是我在sql query中运行是不行的(因为单独运行select 是有数据的)
    -----
      结果:
    (0 row(s) affected)Server: Msg 213, Level 16, State 7, Procedure TT_Select, Line 11
    Insert Error: Column name or number of supplied values does not match table definition.
      

  8.   

    My god!很明顯哪,錯誤訊息是告訊你欄位沒有足。你只需這樣:

    insert into #tmp EXEC [sms].[dbo].[TT_Select] @MyParam 
    改成 insert into #tmp ([Name], [CastType], [ProgramType], [Parent]) EXEC  TT_Select @myParam字段要一一對應。
      

  9.   

    谢谢:N_chow(一劍飄香) 了,
       我看都没看出错信息,实在不好意思....^)^
        
       加分中。