if((select count(*) from opr_.tab_qy_zzqk_sb   where  right(zzsblx,4)='1001' and sbid=@sbid)=0)  begin   select b.id as id,  (a.xm+' '+case IsNull(zjh15,'') when '' then zjh else zjh15 end) as title   from  opr_.view_qy_ryZsAndSb_list a inner join opr_.tab_qy_zcrysb b on (a.ryid=b.ryid) where sbid=@sbid union select zyryid as id,(xm+' '+case IsNull(zjh15,'') when '' then zjh else zjh15 end) as title from  opr_.tab_qy_zyrykcsj_sb where sbid=@sbid end  else  select b.id as id,  (a.xm+' '+case IsNull(zjh15,'') when '' then zjh else zjh15 end) as title   from  opr_.view_qy_ryZsAndSb_list a inner join opr_.tab_qy_zcrysb b on (a.ryid=b.ryid) where sbid=@sbid  union   select b.id as id,  (a.xm+' '+case IsNull(zjh15,'') when '' then zjh else zjh15 end) as title   from  opr_.view_qy_rysbAndzg a inner join opr_.tab_qy_zcrysb b on (a.ryid=b.ryid) where sbid=@sbid union select zyryid as id,(xm+' '+case IsNull(zjh15,'') when '' then zjh else zjh15 end) as title from  opr_.tab_qy_zyrykcsj_sb where sbid=@sbid

解决方案 »

  1.   

    是不是有什么特殊字符 搞ntext試試
      

  2.   

    declare @sbid nvarchar(50)
    set @sbid='1000'
    declare @a nvarchar(4000)
    set @a='if((select count(*) from opr_.tab_qy_zzqk_sb   where  right(zzsblx,4)=''1001'' and sbid=@sbid)=0)  begin   select b.id as id,  (a.xm+'' ''+case IsNull(zjh15,'''') when '''' then zjh else zjh15 end) as title   from  opr_.view_qy_ryZsAndSb_list a inner join opr_.tab_qy_zcrysb b on (a.ryid=b.ryid) where sbid='''+@sbid+''' union select zyryid as id,(xm+'' ''+case IsNull(zjh15,'''') when '''' then zjh else zjh15 end) as title from  opr_.tab_qy_zyrykcsj_sb where sbid='''+@sbid+''' end  else  select b.id as id,  (a.xm+'' ''+case IsNull(zjh15,'''') when '''' then zjh else zjh15 end) as title   from  opr_.view_qy_ryZsAndSb_list a inner join opr_.tab_qy_zcrysb b on (a.ryid=b.ryid) where sbid='''+@sbid+'''  union   select b.id as id,  (a.xm+'' ''+case IsNull(zjh15,'''') when '''' then zjh else zjh15 end) as title   from  opr_.view_qy_rysbAndzg a inner join opr_.tab_qy_zcrysb b on (a.ryid=b.ryid) where sbid='''+@sbid+''' union select zyryid as id,(xm+'' ''+case IsNull(zjh15,'''') when '''' then zjh else zjh15 end) as title from  opr_.tab_qy_zyrykcsj_sb where sbid='''+@sbid+''''
    print @a
    肯定可以存的进的,这段东西的长度才1000,你说的是不能用吧,这样试试
      

  3.   

    1 nr varchar 8000 1还是存不进去报错”输入的值与列的数据类型或长度的长度不一致,或者超出网格缓冲区限制“
      

  4.   

    用nvarcher()类型的去存,varcher()类型是非 Unicode 的字符数据。试一试吧!!
      

  5.   

    你的语句可以插的 你复制 一小段一小段的插入进去 
    或者 定义个变量 按lwl0606(寒泉)
    set 变量 = 你的一长串语句 
    insert into表名(字段名)
    values(变量)
    select * from 表名