把一张表的数据批量插入到另外一张表

limfungsuen 2009-04-14 04:20:42
加精
<%
Server.ScriptTimeOut=600
Set conn=Server.CreateObject("ADODB.Connection")
if err.number<>0 then
err.clear
else
conn.open "Driver={SQL Server};Server=local,1433;UID=sa;PWD=!~@~@#$$432234$$543!;database=DATA;"
end if

set rs=server.createobject("adodb.recordset")
rs.open "select CI_Keywords from TE_CorpInfo where ci_id > 13000 and ci_id<14000",conn,1,1
if not rs.eof and not rs.bof then
for i=1 to rs.recordcount
'response.Write(rs.recordcount)
'response.end
aaa= rs.fields("CI_Keywords").value
bbb=split(aaa," ")
for j=1 to ubound(bbb)-1
set rskey = server.CreateObject("Adodb.Recordset")
rskey.open "select * from SS",conn,1,3
rskey.addnew
rskey("KeyName")= bbb(j)
rskey.update
rskey.close
set rskey=nothing
next
rs.movenext
next
end if
rs.close
conn.close
set conn=nothing
response.Write("success1~~~")
%>


这是一段asp的代码,实现的功能是把TE_CorpInfo的CI_Keywords字段的信息存放到一张新表SS的KeyName字段中去。因为CI_Keywords字段的组成是(a b c d)这种模式,要把CI_Keywords的内容以空格为分隔符,分别存入到SS的KeyName。因为TE_CorpInfo这张表的数据有4万多条,所以执行这段代码,会超过响应时间,虽然我设置了10分钟,后来我只能限制每次的数量为1000条,但是这样效率太低,而且执行速度还是不理想。所以,我想把上述代码改成 纯 SQL的代码,去服务器SQL端执行,但是SQL代码我不是很懂,不知道怎么写来实现这个功能,所以请教各位SQL大侠···

在线等···急急急···
...全文
4183 92 打赏 收藏 转发到动态 举报
写回复
用AI写文章
92 条回复
切换为时间正序
请发表友善的回复…
发表回复
rmini 2009-05-12
  • 打赏
  • 举报
回复
帮顶
soft_wsx 2009-05-12
  • 打赏
  • 举报
回复
学习
cnnbtop 2009-05-11
  • 打赏
  • 举报
回复
建议做个标识符,然后做个任务,处理的话,不要一下全处理,比如做个任务,每隔半小时处理1000条这样,晚上的时候开启任务,这样也不会影响到同事白天上班时候的使用
kelvin_yuwenjing 2009-04-20
  • 打赏
  • 举报
回复
学习
zhaodalong 2009-04-20
  • 打赏
  • 举报
回复
good good study ,
day day up !
  • 打赏
  • 举报
回复
好好学习,天天向上!
tiger_lin 2009-04-20
  • 打赏
  • 举报
回复
学习
bi_8628 2009-04-19
  • 打赏
  • 举报
回复
看不懂代码.
没学过VB,头晕~~
jy02352659 2009-04-19
  • 打赏
  • 举报
回复
眼都看花拉!!!!不过,很好!!顶死你!
benci042 2009-04-19
  • 打赏
  • 举报
回复
还是存储过程吧,
dandelionl 2009-04-19
  • 打赏
  • 举报
回复
mark
careers1111 2009-04-19
  • 打赏
  • 举报
回复
学习一下
pingtanren 2009-04-19
  • 打赏
  • 举报
回复
学好SQL语言 掌握各种数据库技术 加油吧
happy664618843 2009-04-19
  • 打赏
  • 举报
回复
Create table Tab(CI_ID int, CI_Keywords nvarchar(20))
Insert Tab
SELECT 10001, 'sky blue water' UNION ALL
SELECT 10002, 'book apple shirt' UNION ALL
SELECT 10005, 'cup yellow org' UNION ALL
SELECT 61245, 'box phone paper'
Go
create table SSS(KeyID int, KeyName varchar(20))
go

if object_id('Tempdb..#Num') is not null
drop table #Num
go
select top 40000 ID=Identity(int,1,1) into #Num from syscolumns a,syscolumns b

Select id=identity(int,1,1) ,
COl2=substring(replace(a.CI_Keywords, ' ', ','),b.ID,charindex(',',replace(a.CI_Keywords, ' ', ',')+',',b.ID)-b.ID)
into #
from
Tab a,#Num b
where
charindex(',',','+replace(a.CI_Keywords, ' ', ','),b.ID)=b.ID

insert SSS
select * from #

SELECT * FROM SSS

drop table Tab,SSS,#
/*
KeyID KeyName
----------- --------------------
1 sky
2 book
3 cup
4 box
5 blue
6 yellow
7 phone
8 apple
9 water
10 paper
11 shirt
12 org
surge0321 2009-04-19
  • 打赏
  • 举报
回复
学习
jasonmike 2009-04-19
  • 打赏
  • 举报
回复
还是用存储过程比较好。
lhqw2006 2009-04-19
  • 打赏
  • 举报
回复
对于这方面我真的不懂啊,帮顶一下啦
long0127 2009-04-19
  • 打赏
  • 举报
回复
学习了
XWAN521 2009-04-19
  • 打赏
  • 举报
回复
啊啊啊 我会
woshilaolao 2009-04-18
  • 打赏
  • 举报
回复
用视图插入
加载更多回复(70)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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