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

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.