This is my query that I want to insert a value that should be selected from another table:
insert into payment_details_kohin(installment_no)
values(
select count(installment_amount)+2
from kohin_plan.payment_details_insert
where customer_id='KBP100058'
)
... but this gives me an error:
Msg 515, Level 16, State 2, Row 1 Cannot insert NULL value in column "customer_id", table 'Kohinoor_rdfd.kohin_plan.payment_details_kohin'; column Do not allow null. INSERT fails. Application completed.
When trying to execute the following query:
insert into payment_details_kohin(installment_no)
values(
select count(installment_amount)+2
from kohin_plan.payment_details_insert
where customer_id='KBP100058'
)
... this gives me the following error
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ')'.
source
share