帮忙看看sql 的问题(100分)

  • 主题发起人 主题发起人 shanliu
  • 开始时间 开始时间
S

shanliu

Unregistered / Unconfirmed
GUEST, unregistred user!
insert into xscjb(xh,xm,xueqi,bz)
values((select xh from xsxcb where zdh=:zdh_2 and cch=:cch_2 and zyh=:zyh_2
and nj=:nj_2),(select xh from xsxcb where zdh=:zdh_2 and cch=:cch_2
and zyh=:zyh_2 and nj=:nj_2),:kch_2,:c_xq_2,:bz_2)
 
insert into xxx(field1, field2...) select field1, field2... from .....where....

两边的列的数量和类型要对应
 
insert into xscjb(xh,xm.xueqi,bz)
select xh
from xsxcb
where zdh=:zdh_2 and cch=:cch_2 and zyh=:zyh_2 and nj=:nj_2,
:kch_2,:c_xq_2,:bz_2



 

insert into xscjb(xh,xm,xueqi,bz)
select xh,xh,:kch_2,:c_xq_2,:bz_2
from xsxcb where zdh=:zdh_2 and cch=:cch_2 and zyh=:zyh_2 and nj=:nj_2
 
(xh,xm,xueqi,bz)
这四个字段
((select xh from xsxcb where zdh=:zdh_2 and cch=:cch_2 and zyh=:zyh_2
and nj=:nj_2),(select xh from xsxcb where zdh=:zdh_2 and cch=:cch_2
and zyh=:zyh_2 and nj=:nj_2),:kch_2,:c_xq_2,:bz_2)
这里有五个值
 
我写错了 是:
insert into xscjb(xh,xm,kch,xueqi,bz)
values((select xh from xsxcb where zdh=:zdh_2 and cch=:cch_2 and zyh=:zyh_2
and nj=:nj_2),(select xh from xsxcb where zdh=:zdh_2 and cch=:cch_2
and zyh=:zyh_2 and nj=:nj_2),:kch_2,:c_xq_2,:bz_2)
我在DELPHI中写的想在xsxcb 中取数据写入xscjb中,并且是批量的写
 
这样当然不行啦,要批量执行,不不要用values,insert into 后面直跟一条查询,
试一下这样
insert into xscjb(xh,xm,kch,xueqi,bz)
select (select xh from xsxcb where zdh=:zdh_2 and cch=:cch_2 and zyh=:zyh_2
and nj=:nj_2),(select xh from xsxcb where zdh=:zdh_2 and cch=:cch_2
and zyh=:zyh_2 and nj=:nj_2),:kch_2,:c_xq_2,:bz_2 from xsxcb
 
如果你的 子 select 返回一个值,应该没问题。
但返回多个不能这样写
 
:kch_2,:c_xq_2,:bz_2 不是在xsxcb,我想在程序中动态的改变
 
select xh from xsxcb where zdh=:zdh_2 and cch=:cch_2 and zyh=:zyh_2
and nj=:nj_2),select xh from xsxcb where zdh=:zdh_2 and cch=:cch_2 and zyh=:zyh_2
and nj=:nj_2),
這兩句一樣,為什麼要定兩次?select xh,xh from xsxcb where ...可以不?

insert into table
select a.column,b.column,:values from tablea a , tableb b where a.column1=b.column1 and ....
 
这样写:
insert into xscjb(xh,xm,kch,xueqi,bz)
select xh xm from xsxcb where zdh=:zdh_2 and cch=:cch_2 and zyh=:zyh_2
and nj=:nj_2
kch,xueqi,bz,不在任何表中,我要在程序中动态的写入,格式是什么呀!我是老不能
同时插入
 
接受答案了.
 
后退
顶部