Use [Database]
GO
SET ANSI_NULLS on
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo]. [Table name]
As
Begin
DECLARE @Keyword varchar (max), @strs varchar (max)
--Declaring cursors
Declare mtf_cursor Cursor for select distinct Keyword from Keywords where flag=4
--Open cursor
Open Mtf_cursor
FETCH NEXT from Mtf_cursor to @Keyword-moves the cursor down by 1 rows to get the data into the previously defined variable @ @Keyword
While @ @FETCH_STATUS = 0--Returns the state of the cursor when FETCH executes the statement (1:fetch gets the data successfully -1:fetch statement failed or this row is not in the result set-2: The fetched row does not exist)
Begin
Select Productid,productname,row_number () over (order by ProductID) as ROWSS to #tempKeyword from table name where ProductName li Ke '% ' [email protected]+ '% '
SELECT * FROM #tempKeyword
DECLARE @numint
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), +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 to @Keyword-move cursor down 1 rows
End
Close mtf_cursor--Closing Cursors
deallocate mtf_cursor--Release Cursors
End
--exec keywordcontent
The stored procedure looks up the contents of the table to match the corresponding data in another table, inserting the data that the table finds into another table