 DECLARE @testGelieerdePersoonID AS INT;
 DECLARE @testAfdelingsJaarID AS INT;
 DECLARE @testVorigAfdelingsJaarID AS INT;
+DECLARE @testGav1ID AS INT;
 
 ---
 --- Groep en Chirogroep creeren

PRINT 'TestPersoonID: ' + CAST(@testPersoonID AS VARCHAR(10))
PRINT 'TestGelieerdePersoonID: ' + CAST(@testGelieerdePersoonID AS VARCHAR(10))
PRINT 'TestPersoon2ID: ' + CAST(@testPersoon2ID AS VARCHAR(10))

GO

	INSERT INTO pers.GelieerdePersoon(PersoonID, GroepID, ChiroLeeftijd)
	VALUES (@testPersoon2ID, @testGroepID, 0);
END

-- 
-- Users creeren 
--

IF NOT EXISTS (SELECT 1 FROM auth.GAV WHERE Login=@testGav1Login)
BEGIN
	INSERT INTO auth.GAV(Login) VALUES(@testGav1Login);
	SET @testGav1ID = SCOPE_IDENTITY();
END
ELSE
BEGIN
	SET @testGAV1ID =  (SELECT GavID FROM auth.GAV WHERE Login=@testGav1Login)
END

IF NOT EXISTS (SELECT 1 FROM auth.GAV WHERE Login=@testGav2Login)
BEGIN
	INSERT INTO auth.GAV(Login) VALUES(@testGav2Login);
END

--
-- Gebruikersrecht
--

IF NOT EXISTS (SELECT 1 FROM auth.GebruikersRecht WHERE GavID=@testGav1ID AND GroepID=@testGroepID)
BEGIN
	INSERT INTO auth.GebruikersRecht(GavID, GroepID) VALUES(@testGav1ID, @testGroepID)
END



PRINT 'TestGroepID: ' + CAST(@testGroepID AS VARCHAR(10));
