Wednesday, March 28, 2012

how to INSERT from SELECT

why is this syntax incorrect?

INSERT INTO visits (visit_file_no, direct_or_insurance, insurance_company_id, visit_total_amount) VALUES (@.visit_file_no, @.direct_or_insurance, @.insurance_company_id, SELECT item_price FROM price_list WHERE item_code = 'FIRST_VISIT')

I haved all values passed by the windows form but i only need to retrieve the amount from item price table

Jassim:

Try this and see if it works better:

INSERT INTO visits
( visit_file_no,
direct_or_insurance,
insurance_company_id,
visit_total_amount
)
select @.visit_file_no,
@.direct_or_insurance,
@.insurance_company_id,
item_price
from price_list
where item_code = 'FIRST_VISIT'

No comments:

Post a Comment