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

要求:

在表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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值