USE [数据库]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[表名]
as
begin
declare @Keyword varchar(max),@strs varchar(max)
--申明游标
declare MTF_Cursor CURSOR FOR select distinct Keyword from Keywords where Flag=4
--打开游标
open MTF_Cursor
fetch next from MTF_Cursor into @Keyword --将游标向下移1行,获取的数据放入之前定义的变量@@Keyword中
while @@FETCH_STATUS = 0 --返回 FETCH 执行语句时游标的状态(1:fetch获取数据成功 -1:fetch语句失败或此行不在结果集中 -2:被提取的行不存在)
begin
select ProductID,ProductName,ROW_NUMBER() over(order by ProductId) as rowss into #tempKeyword from 表名 where ProductName like ‘%‘[email protected]+‘%‘
select * from #tempKeyword
declare @num int
declare @nums int
select @nums=COUNT(1) from #tempKeyword
set @num=1
while @num<= @nums
begin
declare @productId int
declare @productName varchar(max)
declare @Content varchar(max)
select @productId= ProductId,@productName=ProductName from #tempKeyword where [email protected]
select @Content=dbo.regexReplace(Content,‘<.*?>‘,‘‘,1,0) from ProContent where [email protected]
set @strs=RIGHT(Substring(@Content,0,CHARINDEX(@Keyword,@Content)+1),77)+Substring(@Content,CHARINDEX(@Keyword,@Content)+1,77)
insert into KeywordsContent(Keyword,[type],RecordId,Title,Summary)
values(@Keyword,‘product‘,@productId,@productName,@strs)
set @[email protected]+1
end
drop table #tempKeyword
fetch next from MTF_Cursor into @Keyword --将游标向下移1行
end
close MTF_Cursor--关闭游标
deallocate MTF_Cursor--释放游标
end
--exec KeywordContent