--Insert Agent into UAT Central and appropriate Client databases.
DECLARE @FirstName varchar (50)
DECLARE @LastName varchar (50)
DECLARE @Total int
DECLARE @MolinaAccess int
DECLARE @EmblemAccess int
DECLARE @NewAgentID int
DECLARE @Error int
SET @Total=0
SET @Error=-1
SET @FirstName='Peter'
SET @LastName='Buettner'
SET @MolinaAccess=1
SET @EmblemAccess=1
BEGIN TRANSACTION
USE CCS_Central
SELECT @Total=COUNT(*) FROM Agent
WHERE FirstName=@FirstName
AND LastName=@LastName
PRINT @Total
If @Total > 0
BEGIN
PRINT @FirstName + ' ' + @LastName + ' already exists in Agent table.'
END
SELECT @Total=COUNT(*) FROM AgentClient
WHERE AgentID IN
(
SELECT AgentID FROM Agent
WHERE FirstName=@FirstName
AND LastName=@LastName
)
If @Total > 0
BEGIN
PRINT @FirstName + ' ' + @LastName + ' already exists in AgentClient table.'
END
SELECT @Total=COUNT(*) FROM AgentRole
WHERE AgentID IN
(
SELECT AgentID FROM Agent
WHERE FirstName=@FirstName
AND LastName=@LastName
)
If @Total > 0
BEGIN
PRINT @FirstName + ' ' + @LastName + ' already exists in AgentRole table.'
END
USE CCS_Molina_UAT
SELECT @Total=COUNT(*) FROM Agent
WHERE FirstName=@FirstName
AND LastName=@LastName
If @Total > 0
BEGIN
PRINT @FirstName + ' ' + @LastName + ' already exists in Molina.'
END
USE CCS_Molina_UAT
SELECT @Total=COUNT(*) FROM Agent
WHERE FirstName=@FirstName
AND LastName=@LastName
If @Total > 0
BEGIN
PRINT @FirstName + ' ' + @LastName + ' already exists in Emblem.'
END
if @Total > 0
BEGIN
GoTo EndofScript
END
--Write Agent into appropriate databases.
BEGIN TRANSACTION
USE CCS_Central
INSERT INTO Agent (FirstName,LastName,Active)
VALUES(@FirstName,@LastName,1)
SET @NewAgentID=@@Identity
SET @Error=@@ERROR
INSERT INTO AgentRole (AgentID,RoleID)
VALUES(@NewAgentID,5)
SET @Error=@@ERROR
if @MolinaAccess=1
Begin
USE CCS_Central
INSERT INTO AgentClient (AgentID,ClientID)
VALUES(@NewAgentID,75)
SET @Error=@@ERROR
USE CCS_Molina_UAT
SET Identity_Insert Agent ON
INSERT INTO Agent (AgentID,FirstName,LastName,Active)
VALUES(@NewAgentID,@FirstName,@LastName,1)
SET Identity_Insert Agent OFF
SET @Error=@@ERROR
End
if @EmblemAccess=1
Begin
USE CCS_Central
INSERT INTO AgentClient (AgentID,ClientID)
VALUES(@NewAgentID,2)
SET @Error=@@ERROR
USE CCS_Emblem_UAT
SET Identity_Insert Agent ON
INSERT INTO Agent (AgentID,FirstName,LastName,Active)
VALUES(@NewAgentID,@FirstName,@LastName,1)
SET Identity_Insert Agent OFF
SET @Error=@@ERROR
End
if @Error = -1
Begin
ROLLBACK TRAN
End
else
begin
COMMIT
end
EndofScript:
|