![](/img/trans.png)
[英]How to avoid specifying SQL query on Spring Data JPA when an attribute comes from another table
[英]How to insert data into a table such that one value comes from another table and other value comes from the form
我将数据插入到一个表中,这样一个值来自另一个表,另一个值来自表单。
select
SNO,bill_num,item_type,size,article_num,ind_num
,colour,amount,all_comment,vendor_name,incoice_no
,Bill_Date,Receiving_Date,color_name,MRP,unique_bill_id
into @tid
from DEMO_STOCK_TABLE_KP
where sno='"+ uni_s+"';
@did=d;
insert into SOLD_items_RETAILX
(SNO,bill_num,item_type,size,article_num
,ind_num,colour,amount,all_comment,vendor_name
,incoice_no,Bill_Date,Receiving_Date,color_name
,MRP,unique_bill_id,gst_bill_no) values (@tid,@did);
在一般情况下,如果您想使用表中的值和其他来源(如文字)的混合值执行INSERT
,则可以执行INSERT/SELECT
:
INSERT INTO MyTable (col1, col2, col3)
SELECT src_col1, src_col2, 'some_literal'
FROM MyTable
所以,也许你可以在这里做类似的事情:
insert into SOLD_items_RETAILX (
SNO, bill_num, item_type, size, article_num, ind_num, colour,
amount, all_comment, vendor_name, incoice_no, Bill_Date, Receiving_Date,
color_name, MRP, unique_bill_id, gst_bill_no)
select
SNO, bill_num, item_type, size, article_num, ind_num, colour,
amount, all_comment, vendor_name, incoice_no, Bill_Date, Receiving_Date,
color_name, MRP, unique_bill_id, <gst_bill_no>
from DEMO_STOCK_TABLE_KP
where sno='"+ uni_s+"';
您只需将<gest_bill_no>
占位符替换为正确的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.