Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL SERVER 2017
Some help
Error is line 4
 
I need first column Naziv artikla  (Line 1)
second column Prodata Kolicina (Line 2)
Third column Nabaljena kolicina (Line 4)  some error
Fourth column difference Line4 - Line 2 as Ukupno


What I have tried:

SELECT  roba as 'Naziv artikla',  
SUM (cast(kolicina as float)) as 'Prodata kolicina'   
from (select roba, kolicina from mp_racun_roba union all select roba, kolicina from mp_faktura_roba) as alltables  
INNER JOIN mp_ulazni_racun_ostalo_roba ON alltables.kolicina=mp_ulazni_racun_ostalo_roba.kolicina as 'Nabavljena kolicina'    
--SUM COLUMN 'Nabavljena kolicina' - 'Prodata kolicina'  //result column   
group by roba  
Posted
Comments
OriginalGriff 27-Jul-18 12:10pm    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. So show us what the tables are, give us sampel data, explain what you expect to get, and tell us what the error actually is!

Use the "Improve question" widget to edit your question and provide better information.
Goran Bibic 28-Jul-18 2:53am    
WITH AllTables (roba, kolicina) AS
(
SELECT roba,kolicina FROM MP_RACUN_ROBA
UNION ALL
SELECT roba,kolicina FROM mp_faktura_roba
)

SELECT roba AS 'Naziv artikla',
SUM (cast(kolicina AS float)) AS 'Prodata kolicina'
FROM AllTables AT
INNER JOIN mp_ulazni_racun_ostalo_roba MPU ON AT.kolicina=MPU.kolicina
GROUP BY roba





Like this

Some help

Msg 209, Level 16, State 1, Line 8
Ambiguous column name 'kolicina'.

Line 8 and I need in line one more table mp_ulazni_racun_roba
Naga Sindhura 1-Aug-18 3:23am    
use alias name to select the column and will avoid Ambiguous column errors.
like - kolicina exists in AllTables table the change your select as AT.kolicina : to SUM (cast(AT.kolicina AS float)) AS 'Prodata kolicina'

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