declare @SUBNo int 
select @SUBNo=4
select IDENTITY(int,@SUBNo,1) ID_Num ,a.* INTO #TMP from table a  
提示 '第 6 行: '@SUBNo' 附近有语法错误。'
IDENTITY无法接受参数吗?
如何才能实现通过参数替增的功能!环境:SQL2000

解决方案 »

  1.   

    declare @SUBNo int 
    select @SUBNo=4
    exec('select IDENTITY(int,'+@SUBNo+',1) ID_Num ,a.* INTO #TMP from table a') 
      

  2.   

    那为什么查询select *from #TMP 提示 "对象名 '#TMP' 无效。"不是创建了临时表#TMP吗?
      

  3.   

    declare @SUBNo int 
    select @SUBNo=4
    exec('select IDENTITY(int,'+@SUBNo+',1) ID_Num ,a.* INTO #TMP from table a select *from #TMP') 
      

  4.   

    --OR
    declare @SUBNo int 
    select @SUBNo=4
    exec('select IDENTITY(int,'+@SUBNo+',1) ID_Num ,a.* INTO ##TMP from table a select *from #TMP') 
    select *from ##TMP
      

  5.   

    --手誤
    declare @SUBNo int 
    select @SUBNo=4
    exec('select IDENTITY(int,'+@SUBNo+',1) ID_Num ,a.* INTO ##TMP from table a ') 
    select *from ##TMP
      

  6.   


    declare @SUBNo int 
    select @SUBNo=4
    exec('select IDENTITY(int,'+@SUBNo+',1) ID_Num ,a.* INTO ##TMP from table a ') 
    select *from ##TMP楼上正解。
      

  7.   

    declare @SUBNo int 
    select @SUBNo=4
    exec('select IDENTITY(int,'+@SUBNo+',1) ID_Num ,a.* INTO #TMP from sysobjects  a
    select * from #TMP')
    create table #T(ID int)
    declare @SUBNo int 
    select @SUBNo=4
     exec('select IDENTITY(int,'+@SUBNo+',1) ID_Num INTO #TMP from sysobjects  a
    insert #T select * from #TMP')
    select * from #T
    用動態生成臨時表或全局臨時表

    先建