帮助朋友写的一个存储过程!
2006-07-27 11:54
387 查看
要求:
在表tbStickers 中的一个字段Reply_ID,放在另一个表tbReply_Stickers 中多个记录的ID,并用逗号","隔开,现在要求从tbStickers 读取一个记录,并把存放在Reply_ID中的tbReply_Stickers的多个记录ID关联到tbReply_Stickers 相对应的记录并读取出来!
如下:
ALTER PROCEDURE Stickers_View
@S_ID int
as
Declare @temp int
SET @temp=0
Declare @ResNameCount as varchar(20)
SET @ResNameCount=(select Reply_ID from tbStickers where S_ID=11)
select Theme,Content,Img_Like,Published_Time,IP,img,User_Name into temp from tbStickers where S_ID=11
delete from temp
select @temp=charindex(',',@ResNameCount)
while @temp>0
begin
insert into temp
select Theme,Content,Img_Like,Published_Time,IP,img,User_Name from tbReply_Stickers where RS_ID=left(@ResNameCount,charindex(',',@ResNameCount)-1)
select @ResNameCount=substring(@ResNameCount,charindex(',',@ResNameCount)+1,len(@ResNameCount))
select @temp=charindex(',',@ResNameCount)
end
select Theme,Content,Img_Like,Published_Time,IP,img,User_Name from tbStickers where S_ID=11
union
select * from temp
drop table temp
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
在表tbStickers 中的一个字段Reply_ID,放在另一个表tbReply_Stickers 中多个记录的ID,并用逗号","隔开,现在要求从tbStickers 读取一个记录,并把存放在Reply_ID中的tbReply_Stickers的多个记录ID关联到tbReply_Stickers 相对应的记录并读取出来!
如下:
ALTER PROCEDURE Stickers_View
@S_ID int
as
Declare @temp int
SET @temp=0
Declare @ResNameCount as varchar(20)
SET @ResNameCount=(select Reply_ID from tbStickers where S_ID=11)
select Theme,Content,Img_Like,Published_Time,IP,img,User_Name into temp from tbStickers where S_ID=11
delete from temp
select @temp=charindex(',',@ResNameCount)
while @temp>0
begin
insert into temp
select Theme,Content,Img_Like,Published_Time,IP,img,User_Name from tbReply_Stickers where RS_ID=left(@ResNameCount,charindex(',',@ResNameCount)-1)
select @ResNameCount=substring(@ResNameCount,charindex(',',@ResNameCount)+1,len(@ResNameCount))
select @temp=charindex(',',@ResNameCount)
end
select Theme,Content,Img_Like,Published_Time,IP,img,User_Name from tbStickers where S_ID=11
union
select * from temp
drop table temp
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
相关文章推荐
- 一个用汇编写的引导区病毒例程,有时间可以分析一下,对各位学习汇编的朋友很有帮助!
- 把我给另外一个朋友的炒股劝告发给你一遍,希望你可以得到帮助!
- 在朋友的帮助下对一个函数的改进
- 给各位使用delphi借助CEF开发的朋友一个帮助
- 今天发一个以前下载过的项目经理案头手册吧,希望能给有用的朋友一些帮助。
- 哪位朋友帮助下,我现在在做一个电子地图WebGIS中的轨迹回放,应该怎么做?请告知,谢谢!
- 请求帮助:公司要做一个ASP.NET的项目管理网站,各位朋友有什么好的框架可以推荐?
- 一个IT人士的个人经历,给迷失方向的朋友
- 来自一个朋友
- 做一个会享受生活的程序员从找一个女朋友开始
- 今天登录一个网站,认识好几个朋友!
- 为一个朋友解答的C++小问题
- 给使用Windows Azure的朋友推荐一个新的原创的书《实战Windows Azure:微软云计算平台技术详解》
- 一个存储过程实现(问题答案)
- Android一个画图的例子,希望对画图初学者有帮助
- 以前写的一个分页存储过程,刚才不小心翻出来的
- [全程建模]与一个朋友讨论的关于书上的两个问题
- 做报表时用到的一个存储过程
- 发布一个通用的数据分页的存储过程
- 帮朋友招一个IM开发人员