Click here to Skip to main content
15,923,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Need multiply two column with select statement MSSQL

Error is column quantity2 not exist

What I have tried:

INSERT INTO dbo.table1 (quantity1, quantity2, result)

SELECT quantity1,

(select kolicina as quantity2 from dbo.radni_nalog_roba where id_fakture=(select max(id) from dbo.radni_nalog_lista)),

(quantuty1*quantity2) as ukupno

FROM dbo.table2
Updated 25-May-19 6:22am

1 solution

Without knowing your tables and the interaction between them, I can't be specific and accurate. But what you want to do is a JOIN.
SELECT a.quantity1, b.quantity2 , (a.quantuty1 * b.quantity2) AS ukupno
FROM dbo.table2 a
JOIN (SELECT kolicina AS quantity2 FROM dbo.radni_nalog_roba 
      WHERE id_fakture = (SELECT MAX(id) FROM dbo.radni_nalog_lista)) b
ON a.ID = b.id_fakture
or similar.
Share this answer

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