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
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,你说的是不能用吧,这样试试
或者 定义个变量 按lwl0606(寒泉)
set 变量 = 你的一长串语句
insert into表名(字段名)
values(变量)
select * from 表名