USE AdventureWorksOBP
GO

CREATE OR ALTER PROC p1
	@Ime NVARCHAR (50),
	@Prezime NVARCHAR(50),
	@Email NVARCHAR (50),
	@Telefon NVARCHAR (25),
	@Izlaz NVARCHAR(50) OUTPUT
AS
	IF NOT EXISTS (SELECT * FROM KUPAC AS k WHERE k.Ime LIKE @Ime AND k.Prezime LIKE @Prezime)
		BEGIN
			INSERT INTO Kupac (Ime, Prezime, Email, Telefon)
			VALUES (@Ime, @Prezime, @Email, @Telefon)
			SET @Izlaz = 'Kupac Id : ' + CONVERT(NVARCHAR,SCOPE_IDENTITY())
		END
	ELSE 
		BEGIN
			SET @Izlaz = 'Kupac Id : ' + CONVERT(NVARCHAR,SCOPE_IDENTITY())
		END

DECLARE @poruka NVARCHAR(50)
EXEC p1 'Gustavo', 'Achong', 'gustavo0@adventure-works.com', '398-555-0132', @poruka OUTPUT
PRINT @poruka


DROP PROC p1