declare @photoid varchar(1000)
set @photoid =in(select fileid from photodetail where classid=9) 这样不行啊~我想要这么个结果:
@photoid ='1,2,3,4,5,6,'怎么写才对啊!!! 本人超级菜鸟!!!
大侠贴些代码吧~多帮忙!
set @photoid =in(select fileid from photodetail where classid=9) 这样不行啊~我想要这么个结果:
@photoid ='1,2,3,4,5,6,'怎么写才对啊!!! 本人超级菜鸟!!!
大侠贴些代码吧~多帮忙!
insert into #t select 2
insert into #t select 3
insert into #t select 4
insert into #t select 5
insert into #t select 6declare @s varchar(100)set @s=''select @s=@s + ',' + cast(ID as varchar(100)) from #t
set @s=stuff(@s,1,1,'')select @sdrop table #t
--返回:1,2,3,4,5,6
from photodetail
where classid=9--去掉最末尾的逗号
set @photoid=stuff(@photoid,1,1,'')select @photoid
1、用变量实现查询结果的合并计算
2、stuff避免了right或replace或substring等复杂处理
from photodetail
where classid=9--去掉最开头的逗号
set @photoid=stuff(@photoid,1,1,'')select @photoid
select @photoid =@photoid + (select rtrim(ltrim(fileid)) from photodetail where classid=9) + ','
select @photoid=ltrim(rtrim(@photoid))
select @photoid=left(@photoid,len(@photoid)-1)
http://www.v2studio.cn/blog/gaojier/article.asp?id=21