您的位置:首页 > 其它

帮助朋友写的一个存储过程!

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: