use fff
go
create function data_insert1()
RETURNS int
Begin
Declare @qq int(4)
declare @table_index int(4),@tj int(4),@yj int(4),@ej int(4),@sj int(4),@sij bigint(8)
declare @wj bigint(8),@lj bigint(8),@zs bigint(8),@zjl char(15),@table_name char(15)
declare youbiao cursor for select * from jj for read only
open youbiao
fetch next from youbiao into @table_index,@qq,@tj,@yj,@ej,@sj,@sij,@wj,@lj,@zs,@zjl
while @@fetch_status=0 /*loop rows in the cursor*/
begin
declare youbiao_temp cursor for
select 数据表名 from table_index where 序号=@table_index
open youbiao_temp
fetch next from youbiao_temp into @table_name
insert @table_name(qq,tj,yj,ej,sj,sij,wj,lj,zs,zjl)
values(@qihao,@tj,@yj,@ej,@sj,@sij,@wj,@lj,@zs,@zjl)
deallocate youbiao_temp
end
deallocate youbiao
RETURN @table_index
end
go
答:肯定的是,这种方法可行。所犯的错误是没有理解 字段名,表名,数据库名之类作为变量时,必须用动态SQL,使用动态sql语句就能解决该问题.
use fff
go
create function data_insert1()
RETURNS int
Begin
Declare @qq int(4)
declare @table_index int(4),@tj int(4),@yj int(4),@ej int(4),@sj int(4),@sij bigint(8)
declare @wj bigint(8),@lj bigint(8),@zs bigint(8),@zjl char(15),@table_name char(15)
declare youbiao cursor for select 数据库表名,qq,tj,yj,ej,sj,sij,wj,lj,zs,zjl from jj a,table_index b where a.table_index=b.序号 for read only
open youbiao
fetch next from youbiao into @table_name,@qq,@tj,@yj,@ej,@sj,@sij,@wj,@lj,@zs,@zjl
while @@fetch_status=0 /*loop rows in the cursor*/
begin
declare @s Nvarchar(1000)
set @s = ''insert '' + @table_name + ''(qq,tj,yj,ej,sj,sij,wj,lj,zs,zjl)'' values''+''(''+@qq+'',''+@tj+'',''+@yj+'',''+@ej+'',''+@sj+'',''+@sij+'',''+@wj+'',''+@lj+'',''+@zs+'',''+@zjl+'')''
Exec(@s)
exec sp_executesql @s
open youbiao
fetch next from youbiao into @table_name,@qq,@tj,@yj,@ej,@sj,@sij,@wj,@lj,@zs,@zjl
end
deallocate youbiao
RETURN 1
end
go
选择5ucms.org 选择未来
上一篇:5ucms帮助安防有道:实施自动的SQL注入攻击测试 下一篇:5ucms插件,[Sql server]最新2005 SP1 的新特性 |
|
本站声明:本网站所载文章等内容,目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权及其它问题,请在30日内与本网联系(Email:3876307#qq.com),我们将在第一时间删除内容。若原创内容转载请注明出处。 5ucms插件,“偷懒”也能更新数据表的关键词: |