Click here to Skip to main content
14,304,321 members
Rate this:
Please Sign up or sign in to 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
Posted
Updated 25-May-19 6:22am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
Try
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.
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100