DECLARE @GroupId int;
DECLARE @UserId int;
DECLARE @UserId1 int;
DECLARE @UserId2 int;
DECLARE @UserId3 int;
DECLARE @UserId4 int;
DECLARE @UserId5 int;
DEClARE @UserId6 int;
DEClARE @UserId7 int;



	-- Admin hệ thống
SET @GroupId = (SELECT TOP 1 Id FROM [dbo].[UserGroup] WHERE Name = N'Admin hệ thống')

IF @GroupId IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroup]
			   ([Name]
			   ,[Desc])
		 VALUES
			   (N'Admin hệ thống', N'Admin hệ thống')

	SET @GroupId = SCOPE_IDENTITY();

	INSERT INTO [dbo].[GroupRole]
			   ([GroupId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@GroupId,13,'x'),
			   (@GroupId,14,'x'),
			   (@GroupId,15,'x'),
			   (@GroupId,17,'x'),
			   (@GroupId,20,'x'),
			   (@GroupId,22,'x'),
			   (@GroupId,99,'x')
END

	-- Add Hứa Đức Lâm
SET @UserId = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='lamhd')

IF @UserId IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Hứa Đức Lâm', 'lamhd', NULL, NULL, '59ca29169ce8e00f74a4b121', 1, 0, 0, 0, 0, NULL)

	SET @UserId = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@UserId,1,'x'),
			(@UserId,2,'ALL'),
			(@UserId,3,'ALL'),
			(@UserId,4,'ALL'),
			(@UserId,5,'ALL'),
			(@UserId,13,'x'),
			(@UserId,14,'x'),
			(@UserId,15,'x'),
			(@UserId,16,'x'),
			(@UserId,17,'x'),
			(@UserId,18,'x'),
			(@UserId,19,'x'),
			(@UserId,20,'x'),
			(@UserId,21,'x'),
			(@UserId,22,'x'),
			(@UserId,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId)
END

	-- Add Hoàng Trọng Tú
SET @UserId4 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='tuhtmsc')

IF @UserId4 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Hoàng Trọng Tú', 'tuhtmsc', NULL, NULL, '5bc46e8dfc460a2954f60461', 1, 0, 0, 0, 0, NULL)

	SET @UserId4 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@UserId4,1,'x'),
			(@UserId4,2,'ALL'),
			(@UserId4,3,'ALL'),
			(@UserId4,4,'ALL'),
			(@UserId4,5,'ALL'),
			(@UserId4,13,'x'),
			(@UserId4,14,'x'),
			(@UserId4,15,'x'),
			(@UserId4,16,'x'),
			(@UserId4,17,'x'),
			(@UserId4,18,'x'),
			(@UserId4,19,'x'),
			(@UserId4,20,'x'),
			(@UserId4,21,'x'),
			(@UserId4,22,'x'),
			(@UserId4,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId4) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId4)
END

	-- Add Đỗ Hữu Phúc
SET @UserId5 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='phucdh')

IF @UserId5 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Đỗ Hữu Phúc', 'phucdh', NULL, NULL, '5bd80c0db85fc03de0936043', 1, 0, 0, 0, 0, NULL)

	SET @UserId5 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@UserId5,1,'x'),
			(@UserId5,2,'ALL'),
			(@UserId5,3,'ALL'),
			(@UserId5,4,'ALL'),
			(@UserId5,5,'ALL'),
			(@UserId5,13,'x'),
			(@UserId5,14,'x'),
			(@UserId5,15,'x'),
			(@UserId5,16,'x'),
			(@UserId5,17,'x'),
			(@UserId5,18,'x'),
			(@UserId5,19,'x'),
			(@UserId5,20,'x'),
			(@UserId5,21,'x'),
			(@UserId5,22,'x'),
			(@UserId5,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId5) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId5)
END

	-- Add Trần Thị Mến
SET @UserId6 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='tranthimen19850007')

IF @UserId6 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Trần Thị Mến', 'tranthimen19850007', NULL, NULL, '58a31aa14971b3245c1e396d', 1, 0, 0, 0, 0, NULL)

	SET @UserId6 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
			(@UserId6,1,'x'),
			(@UserId6,2,'ALL'),
			(@UserId6,3,'ALL'),
			(@UserId6,4,'ALL'),
			(@UserId6,5,'ALL'),
			(@UserId6,13,'x'),
			(@UserId6,14,'x'),
			(@UserId6,15,'x'),
			(@UserId6,16,'x'),
			(@UserId6,17,'x'),
			(@UserId6,18,'x'),
			(@UserId6,19,'x'),
			(@UserId6,20,'x'),
			(@UserId6,21,'x'),
			(@UserId6,22,'x'),
			(@UserId6,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId6) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId6)
END

	-- Add Xuân Trường
SET @UserId7 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='xuantruong')

IF @UserId7 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Xuân Trường', 'xuantruong', 'truongnx060405@gmail.com', NULL, '5baca498b85fb8145810c715', 1, 0, 0, 0, 0, NULL)

	SET @UserId7 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
			(@UserId7,1,'x'),
			(@UserId7,2,'ALL'),
			(@UserId7,3,'ALL'),
			(@UserId7,4,'ALL'),
			(@UserId7,5,'ALL'),
			(@UserId7,13,'x'),
			(@UserId7,14,'x'),
			(@UserId7,15,'x'),
			(@UserId7,16,'x'),
			(@UserId7,17,'x'),
			(@UserId7,18,'x'),
			(@UserId7,19,'x'),
			(@UserId7,20,'x'),
			(@UserId7,21,'x'),
			(@UserId7,22,'x'),
			(@UserId7,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId7) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId7)
END

-- Admin chung
SET @GroupId = (SELECT TOP 1 Id FROM [dbo].[UserGroup] WHERE Name=N'Admin chung')

IF @GroupId IS NULL
BEGIN	
	INSERT INTO [dbo].[UserGroup]
			   ([Name]
			   ,[Desc])
		 VALUES
			   ('Admin chung','ADMIN')

	SET @GroupId = SCOPE_IDENTITY();

	INSERT INTO [dbo].[GroupRole]
			   ([GroupId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@GroupId,1,'x'),
			   (@GroupId,2,'ALL'),
			   (@GroupId,4,'ALL'),
			   (@GroupId,13,'x'),
			   (@GroupId,14,'x'),
			   (@GroupId,15,'x'),
			   (@GroupId,16,'x'),
			   (@GroupId,17,'x'),
			   (@GroupId,18,'x'),
			   (@GroupId,19,'x'),
			   (@GroupId,20,'x'),
			   (@GroupId,99,'x')
END

	-- Add Hứa Thị Du
SET @UserId1 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='duhua')

IF @UserId1 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Hứa Thị Du', 'duhua', NULL, NULL, '5bacaa36b85fb8145810c73f', 1, 0, 0, 0, 0, NULL)

	SET @UserId1 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserGroupMapping]
			   ([GroupId]
			   ,[UserId])
		 VALUES
			   (@GroupId,@UserId1)

	INSERT INTO [dbo].[UserRole]
			   ([UserId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@UserId1,1,'x'),
			   (@UserId1,2,'ALL'),
			   (@UserId1,3,'ALL'),
			   (@UserId1,4,'ALL'),
			   (@UserId1,5,'ALL'),
			   (@UserId1,13,'x'),
			   (@UserId1,14,'x'),
			   (@UserId1,15,'x'),
			   (@UserId1,16,'x'),
			   (@UserId1,17,'x'),
			   (@UserId1,18,'x'),
			   (@UserId1,19,'x'),
			   (@UserId1,20,'x'),
			   (@UserId1,21,'x'),
			   (@UserId1,99,'x')
END

	-- Add Hứa Thị Lê
SET @UserId2 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='leht')

IF @UserId2 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Hứa Thị Lê', 'leht', NULL, NULL, '58a6957c9ce8da0fd8309d0d', 1, 0, 0, 0, 0, NULL)

	SET @UserId2 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserGroupMapping]
			   ([GroupId]
			   ,[UserId])
		 VALUES
			   (@GroupId,@UserId2)

	INSERT INTO [dbo].[UserRole]
			   ([UserId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@UserId2,1,'x'),
			   (@UserId2,2,'ALL'),
			   (@UserId2,3,'ALL'),
			   (@UserId2,4,'ALL'),
			   (@UserId2,5,'ALL'),
			   (@UserId2,13,'x'),
			   (@UserId2,14,'x'),
			   (@UserId2,15,'x'),
			   (@UserId2,16,'x'),
			   (@UserId2,17,'x'),
			   (@UserId2,18,'x'),
			   (@UserId2,19,'x'),
			   (@UserId2,20,'x'),
			   (@UserId2,21,'x'),
			   (@UserId2,99,'x')
END

-- Add Hứa Đức Lâm
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId)
END

-- Add Hoàng Trọng Tú
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId4) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId4)
END

-- Add Đỗ Hữu Phúc
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId5) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId5)
END

-- Add Trần Thị Mến
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId6) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId6)
END

-- Add Xuân Trường
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId7) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId7)
END

	-- IT bệnh viện
SET @GroupId = (SELECT TOP 1 Id FROM [dbo].[UserGroup] WHERE Name=N'IT bệnh viện')

IF @GroupId IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroup]
			   ([Name]
			   ,[Desc])
		 VALUES
			   (N'IT bệnh viện',N'IT bệnh viện')

	SET @GroupId = SCOPE_IDENTITY();

	INSERT INTO [dbo].[GroupRole]
			   ([GroupId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@GroupId,2,'ALL'),
			   (@GroupId,4,'ALL'),
			   (@GroupId,14,'x'),
			   (@GroupId,17,'x'),
			   (@GroupId,99,'x')
END

	-- Bác sĩ chẩn đoán hình ảnh
SET @GroupId = (SELECT TOP 1 Id FROM [dbo].[UserGroup] WHERE Name=N'Bác sĩ CĐHA')

IF @GroupId IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroup]
			   ([Name]
			   ,[Desc])
		 VALUES
			   (N'Bác sĩ CĐHA',N'Bác sĩ chẩn đoán hình ảnh')

	SET @GroupId = SCOPE_IDENTITY();

	INSERT INTO [dbo].[GroupRole]
			   ([GroupId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@GroupId,2,'ALL'),
			   (@GroupId,3,'ALL'),
			   (@GroupId,4,'ALL'),
			   (@GroupId,5,'ALL'),
			   (@GroupId,21,'x')
END

	-- Add Du HT
SET @UserId3 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='duht')

IF @UserId3 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Du HT', 'duht', NULL, NULL, '5b3c40c8edcd6441b8416654', 1, 0, 0, 0, 0, NULL)

	SET @UserId3 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserGroupMapping]
			   ([GroupId]
			   ,[UserId])
		 VALUES
			   (@GroupId,@UserId3)

	INSERT INTO [dbo].[UserRole]
			   ([UserId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@UserId3,2,'ALL'),
			   (@UserId3,3,'ALL'),
			   (@UserId3,4,'ALL'),
			   (@UserId3,5,'ALL'),
			   (@UserId3,21,'x')
END

-- Add Hứa Thị Du
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId1) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
			 ([GroupId]
			,[UserId])
		VALUES
			(@GroupId,@UserId1)
END

-- Add Hứa Thị Lê
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId2) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
			 ([GroupId]
			,[UserId])
		VALUES
			(@GroupId,@UserId2)
END

-- Add Hứa Đức Lâm
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId)
END

-- Add Hoàng Trọng Tú
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId4) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId4)
END


-- Add Đỗ Hữu Phúc
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId5) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId5)
END

-- Add Trần Thị Mến
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId6) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId6)
END

-- Add Xuân Trường
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId7) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId7)
END

-- Kĩ thuật viên
SET @GroupId = (SELECT 1 Id FROM [dbo].[UserGroup] WHERE Name = N'Kĩ thuật viên' )
IF @GroupId IS NULL
BEGIN
INSERT INTO [dbo].[UserGroup]
           ([Name]
           ,[Desc])
     VALUES
           (N'Kĩ thuật viên',N'Kĩ thuật viên')

SET @GroupId = SCOPE_IDENTITY();

INSERT INTO [dbo].[GroupRole]
           ([GroupId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@GroupId,2,'ALL'),
		   (@GroupId,3,'DR, DRo, DX, CR'),
		   (@GroupId,4,'ALL'),
		   (@GroupId,5,'DR, DRo, DX, CR'),
		   (@GroupId,8,'x'),
		   (@GroupId,10,'x'),
		   (@GroupId,12,'x'),
		   (@GroupId,21,'x'),
		   (@GroupId,23,'x')
END

-- Bác sĩ lâm sàng
SET @GroupId = (SELECT 1 Id FROM [dbo].[UserGroup] WHERE Name = N'Bác sĩ lâm sàng' )
IF @GroupId IS NULL
BEGIN
INSERT INTO [dbo].[UserGroup]
           ([Name]
           ,[Desc])
     VALUES
           (N'Bác sĩ lâm sàng',N'Bác sĩ lâm sàng')

SET @GroupId = SCOPE_IDENTITY();

INSERT INTO [dbo].[GroupRole]
           ([GroupId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@GroupId,2,'ALL')
END

-- Quản lý bệnh viện
SET @GroupId = (SELECT 1 Id FROM [dbo].[UserGroup] WHERE Name = N'Quản lý bệnh viện' )
IF @GroupId IS NULL
BEGIN
INSERT INTO [dbo].[UserGroup]
           ([Name]
           ,[Desc])
     VALUES
           (N'Quản lý bệnh viện',N'Quản lý bệnh viện')

SET @GroupId = SCOPE_IDENTITY();

INSERT INTO [dbo].[GroupRole]
           ([GroupId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@GroupId,2,'ALL'),
		   (@GroupId,4,'ALL'),
		   (@GroupId,7,'x'),
		   (@GroupId,8,'x'),
		   (@GroupId,12,'x')
END

-- Demo
SET @GroupId = (SELECT 1 Id FROM [dbo].[UserGroup] WHERE Name = 'Demo' )
IF @GroupId IS NULL
BEGIN
INSERT INTO [dbo].[UserGroup]
           ([Name]
           ,[Desc])
     VALUES
           ('Demo','DEMO')

SET @GroupId = SCOPE_IDENTITY();

INSERT INTO [dbo].[GroupRole]
           ([GroupId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@GroupId,2,'ALL'),
		   (@GroupId,4,'ALL'),
		   (@GroupId,6,'x')
END

-- Add user vào branch tổng ( thêm vào bảng BranchUser)
INSERT [dbo].[BranchUser]
(
[BranchId],
[UserId],
[Active]
)
VALUES 
(NULL, @UserId, 1),
(NULL, @UserId1, 1),
(NULL, @UserId2, 1),
(NULL, @UserId3, 1),
(NULL, @UserId4, 1),
(NULL, @UserId5, 1),
(NULL, @UserId6, 1),
(NULL, @UserId7, 1)

GO