set @sqlstr= N'select identity(int,1,1) as Nid,cast(fid as int) fid,wjm,lwjg,fwh,swh,fs,swsj,clyj,clyjsj,cljg,cljgsj,sfjs,psqx,fjys,bz,
case mj 
when 0 then ''普通''
when 1 then ''机密''
when 2 then ''绝密''
end as mjname 
into ##temp from tfile '

解决方案 »

  1.   

    将其中一对单引号改为双引号。
    set @sqlstr="select identity(int,1,1) as Nid,cast(fid as int) fid,wjm,lwjg,fwh,swh,fs,swsj,clyj,clyjsj,cljg,cljgsj,sfjs,psqx,fjys,bz into ##temp from tfile "
      

  2.   


    declare @sqlstr char(300)
    set @sqlstr="select identity(int,1,1) as Nid,cast(fid as int) fid,wjm,lwjg,fwh,swh,fs,swsj,clyj,clyjsj,cljg,cljgsj,sfjs,psqx,fjys,bz,case mj 
    when 0 then ''普通''
    when 1 then ''机密''
    when 2 then ''绝密''
    end as mjname into ##temp from tfile "
     
    exec (@sqlstr)-------------------------------------------------
    服务器: 消息 103,级别 15,状态 7,行 2
    以 'select identity(int,1,1) as Nid,cast(fid as int) fid,wjm,lwjg,fwh,swh,fs,swsj,clyj,clyjsj,cljg,cljgsj,sfjs,psqx,fjys,bz,case mj ' 开头的 标识符 太长。最大长度为 128。
    -------------------------------------------------为什么 ??help
    select * from ##tempdrop table ##temp
      

  3.   

    不會吧:declare @sqlstr char(300)
    改成
    declare @sqlstr nvarchar(1000)
    試試