Goran Bibic

Goran Bibic

  • 482
  • 2.9k
  • 195.4k

Incorrect Syntax MS SQL

Jan 25 2024 9:41 AM

Try to add in left join UNION ALL

SELECT
    naziv AS 'Naziv',
    SUM(Kol_potr_repromat) AS 'Sum_Kol_potr_repromat'
FROM (
    SELECT
        t.naziv,
        t.kolicina * SUM(s.kolicina) AS 'Kol_potr_repromat'
    FROM
        dbo.normativi_roba t
    LEFT JOIN
        normativi_lista k ON t.id_fakture = k.id
    LEFT JOIN
	(
	SELECT * FROM DBO.mp_racun_roba a
		WHERE
        s.roba IN (SELECT naziv FROM dbo.roba_usluge WHERE podgrupa_artikala = 'HRANA')
        UNION ALL
        select * from mp_faktura_roba a -- ON k.naziv = a.roba
	    WHERE a.roba IN (SELECT naziv FROM dbo.roba_usluge WHERE podgrupa_artikala = 'HRANA')
	)
	ON k.naziv = a.roba AND k.naziv = a.roba
    GROUP BY
        t.naziv, t.jedinica_mjere, t.kolicina
) AS SubqueryAlias
GROUP BY
    naziv;

Errorin line 21:

Incorrect syntax near the keyword 'ON'.


Answers (3)