帮忙小小的改造一下这个存储过程,谢谢

seesea125 2007-04-07 06:25:48
现在的存储过程是这样的
create PROCEDURE dbo.sp_vd_VideoInfo_relate
@id int
AS
declare @ss varchar(50)
select @ss=keywords from dbo.vd_VideoInfo where id=@id
declare my_cursor cursor scroll dynamic /*scroll表示可随意移动游标指针(否则只能向前),dynamic表示可以读写游标(否则游标只读)*/
for
select * from dbo.f_SplitList (',',@ss)


open my_cursor
declare @name sysname
fetch next from my_cursor into @name
while(@@fetch_status=0)
begin
--插入数据
INSERT INTO vd_relate(id,relateid) select @id,id from dbo.vd_VideoInfo where ','+keywords+',' like '%,'+@name+',%'
fetch next from my_cursor into @name
end
close my_cursor
deallocate my_cursor
--去掉本身的新闻id
select distinct * from vd_relate where id<>@id


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

这个存储过程是根据传递过来的参数id,来查找新闻表lc_newsinfo这一条,然后生成她相关的新闻的,放入vd_relate表中,其中里面用到的SplitList函数就不用管它先

我现在要改造成,不要输入参数了,直接把这个新闻表lc_newsinfo循环一遍,然后一条一条生成,因为我要定义成一个作业然它自动运行呢,所以要这么改造,谢谢
...全文
220 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovedick 2007-04-10
  • 打赏
  • 举报
回复
再做个过程吧,循环调用那个过程就可以啦
ankor 2007-04-07
  • 打赏
  • 举报
回复
create PROCEDURE dbo.sp_vd_VideoInfo_relate
AS
declare my_cursor cursor scroll dynamic /*scroll表示可随意移动游标指针(否则只能向前),dynamic表示可以读写游标(否则游标只读)*/
for
select keywords from dbo.vd_VideoInfo

open my_cursor
declare @name sysname
fetch next from my_cursor into @name
while(@@fetch_status=0)
begin
--插入数据
INSERT INTO vd_relate(id,relateid) select @id,id from dbo.vd_VideoInfo where keywords like '%,'+@name+',%'
fetch next from my_cursor into @name
end
close my_cursor
deallocate my_cursor
--去掉本身的新闻id
select distinct * from vd_relate where id<>@id


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧