ALTER PROCEDURE [HM].[hm_KorektaDkZm]

@iddokkoryg INT

AS

BEGIN

	IF (SELECT subtyp FROM hm.zo where id = @iddokkoryg) in (109, 122)
	BEGIN
		SELECT ZO.id, ZO.kod, ZO.data, ZO.bufor, ZO.netto, ZO.iddokkoryg, ZO.vat, ZO.guid
		FROM ZO WITH (INDEX(IDX_ZO_IDDOKKORYG))
		WHERE ZO.iddokkoryg = @iddokkoryg
	END
	ELSE
	BEGIN
		SELECT ZO.id, ZO.kod, ZO.data, ZO.bufor, ZO.netto, ZO.iddokkoryg, ZO.vat, ZO.guid
		FROM ZO WITH (INDEX(IDX_ZO_IDDOKKORYG))
		WHERE ZO.iddokkoryg = @iddokkoryg AND ZO.anulowany <> 1
	END
END
