存储过程查找表中的内容去匹配另一张表中对应的数据,将该表查找到的数据插入到另一张表中

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

时间: 2024-07-30 13:46:00

存储过程查找表中的内容去匹配另一张表中对应的数据,将该表查找到的数据插入到另一张表中的相关文章

解决 Json 中 Html 内容因为反编译带有&quot;\&quot;导致 WebView 无法直接加载问题(字符串的查找与替换)

NSString *path = [[NSBundle mainBundle] pathForResource:@"ad_type = 4" ofType:@"html"]; NSString *htmlStr = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; if (htmlStr != nil && [htmlStr rangeO

table表格单元格中的内容如何强制换行

table表格单元格中的内容如何强制换行:有时候表格单元格中的内容不会换行,那么这个就会严重影响到用户体验,下面就简单介绍一下如何实现单元格中的内容换行.代码实例如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.51texiao.cn/" />

JavaScript解决select下拉框中的内容太长显示不全的问题

JavaScript解决select下拉框中的内容太长显示不全的问题 1.说明 有些情况下,select下拉框的内容过长,导致部分看不见: 现在通过鼠标事件,让下拉框中的内容显示完全 2.实现源码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html

在java中读取文件中的内容

1 package shi; 2 3 import java.io.*; 4 5 public class wenjianIO { 6 public static void main(String agrs[]){ 7 FileInputStream fis=null; 8 File f=new File("F:/test/javakc.txt"); 9 10 try { 11 fis=new FileInputStream(f); 12 byte[]arr=new byte[(int

merge into 实现向表中更新内容&#183;

表触发器2.0 行触发器获取的值改为放在中间表中 触发器在向目标表中写数据时,目标表的记录可能不完全,需要向目标表添加不存在的数据. 用到merge into 语法. merge into  要更新的表(目标表) using  记录完整的表(源表) on  两表记录对比条件 when matched then update when not matched then insert 注意:执行过程是源表中记录一条一条去匹配目标表内容,所以源表中数据不能有符合对比条件的重复数据 另:    某语句要

linux命令---查找文件中的内容

linux命令---查找文件中的内容 [[email protected] ~]$ cat 1.txt |egrep '123456789|second'-------匹配123456789或者second的行 first line:123456789012345678901234567890123456789012345678901234567890 second line:one two three four five six seven eight nine ten [[email pro

SQL语句:关于复制表结构和内容到另一张表中的SQL语句

1.复制新表结构及数据到新表create table 新表 select * from 旧表 2.只复制表结构到新表 create table 新表 select * from 旧表 where 1=2 3.复制旧表的数据到新表(假设两个表结构一样) insert into 新表 select * from 旧表 4.复制旧表的数据到新表(假设两个表结构不一样) insert into 新表(字段1,字段2,......) select 字段1, 字段2,... from 旧表 SQL语句:关于

嵌入式表单字段中的内容可能被服务器更改以删除不安全的内容。是否要重新加载您的页面以查看保存结果?

嵌入式表单字段中的内容可能被服务器更改以删除不安全的内容.是否要重新加载您的页面以查看保存结果? 最近有朋友问到,当他在SharePoint首页上进行编辑时,插入一段代码.完工后保存就遇到了这个问题. 无论选"是"或"否",保存完毕后在设计视图中都看不到效果,查看代码视图,对应的代码也被删除掉了. 这确实是很恼人,好不容易写了那么多东西,结果最后被SPD自己搞没了,如果之前备份了还好,否则,大半天的成果就不翼而飞了. 首先,关于这个问题的定性要清楚.它不是一个错误:

读取Webpage表中的内容

nutch将从网页中抓取到的信息放入hbase数据库中,默认情况下表名为$crawlId_webpage,但表中的内容以16进制进行表示,直接scan或者通过Java API进行读取均只能读取到16进制信息. 因此nutch提供了readdb选项进行数据获取,将表中的内容读取到一个文本中. 具体用法为: $ bin/nutch readdb Usage: WebTableReader (-stats | -url [url] | -dump <out_dir> [-regex regex])