Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to insert value into table called sales (scriptname,accnum,remainingshares) from table transac (scriptname,accnum,sharesbought,sharesold).
I want to calculate remainingshares = sharesbough - sharesold.

Can I do this by the following query??
SQL
INSERT INTO sales(accnum, scriptname, remainingshares) 
select accnum,scriptname,sharesbought-sharesold
from transac
Posted
Updated 11-Sep-15 10:08am
v2
Comments
Schatak 11-Sep-15 7:22am    
Yes you can do it by this query
INSERT INTO sales(accnum, scriptname, remainingshares) select accnum,scriptname,(sharesbought-sharesold) remainingshares from transac

1 solution

Try to set a column alias:
(sharesbough - sharesold) as remainingshares.
 
Share this answer
 
Comments
Maciej Los 11-Sep-15 16:10pm    
Sounds reasonable. +5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900