![](/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.