pb 表1的字段插入表2,字段个数不相同怎末操作??

tian8421 2009-04-13 11:27:05
在pb中实现table1(a,b,c,d) table2(a,b,c,d,e)把table2中的a b c 3个字段插入table1的字段a,b,c,d中 对应关系是这样:
table2---->table1
a---->a
b---->b
c---->c
c---->d 即:table2的c字段 两次插入table1 中。(字段类型已经对应相同)

看我的代码哪里有问题:
insert into "table1"
("a",
"b",
"c",
"d")
select "table2".
"a",
"b",
"c",
"c"
from "table2"
这样写有问题,请问如何实现我想要的操作??谢谢!!
...全文
109 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hxbkkk 2009-04-13
  • 打赏
  • 举报
回复
insert into "table1"
(a,
b,
c,
d)
select
a,
b,
c,
c
from "table2"
newease 2009-04-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 tian8421 的帖子:]
在pb中实现table1(a,b,c,d) table2(a,b,c,d,e)把table2中的a b c 3个字段插入table1的字段a,b,c,d中 对应关系是这样:
table2---->table1
a---->a
b---->b
c---->c
c---->d 即:table2的c字段 两次插入table1 中。(字段类型已经对应相同)

看我的代码哪里有问题:
insert into "table1"
("a",
"b",
"c",
"d")
select "table2".
"a",
"b",
"c",
"c"
from "table2"
这样写有…
[/Quote]

你的思路是对的,格式如下
说明:拷贝表(拷贝数据,源表名:a 目标表名:b)
insert into b(a, b, c) select d,e,f from b;

你的代码应写为
insert into table1 (a,b,c,d)
select a,b,c,c
from table2;
wuliao5945 2009-04-13
  • 打赏
  • 举报
回复
insert into table1
select a,b,c,c
from table2;
desegou 2009-04-13
  • 打赏
  • 举报
回复
insert into "table1" 去掉into
WorldMobile 2009-04-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 tian8421 的帖子:]
在pb中实现table1(a,b,c,d) table2(a,b,c,d,e)把table2中的a b c 3个字段插入table1的字段a,b,c,d中 对应关系是这样:
table2---->table1
a---->a
b---->b
c---->c
c---->d 即:table2的c字段 两次插入table1 中。(字段类型已经对应相同)

看我的代码哪里有问题:
insert into "table1"
("a",
"b",
"c",
"d")
select "table2".
"a",
"b",
"c",
"c"
from "table2"
这样写有…
[/Quote]

你的问题主要是表的别名的问题,因为你的两个表有一些字段一样,建议你这么写
insert into "table1"
("a", "b", "c", "d")
select G.a, G.b, G.c, G.c
from "table2" G
即可
tianqin625 2009-04-13
  • 打赏
  • 举报
回复
大家说的都不错~~
思路对的 小问题而已。

752

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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