

--INSERT SCRIPT FOR CRGroup

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Accounts Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Accounts Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Billing Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Billing Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Branching Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Branching Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Case Detail Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Case Detail Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Client Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Client Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Code List Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Code List Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Creditors Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Creditors Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Debtors Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Debtors Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Diary/Task Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Diary/Task Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Dictation Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Dictation Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'EFT Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('EFT Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Exception Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Exception Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Fees Issued Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Fees Issued Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Fees Received Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Fees Received Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'File Manager')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('File Manager', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'KPI Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('KPI Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Matter Ledger Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Matter Ledger Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Matter List')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Matter List', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Month End Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Month End Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'No Branching')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('No Branching', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Other')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Other', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'PI Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('PI Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Profit And Loss Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Profit And Loss Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Profitibility Report')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Profitibility Report', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Statute of Limitations')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Statute of Limitations', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Time Ledger Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Time Ledger Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Time Reports')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Time Reports', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Time Reports (Billed)')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Time Reports (Billed)', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Time Reports (Unbilled/WIP)')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Time Reports (Unbilled/WIP)', GETDATE(), null, null)
End
Go

IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRGroup] WHERE [groupname] = 'Undertakings')
Begin  
INSERT INTO[dbo].[KaaS_CRGroup]([groupname], [created_on], [modified_on], [status]) VALUES('Undertakings', GETDATE(), null, null)
End
Go


--INSERT SCRIPT FOR CRReport Group


DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Bill Layout' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Billing Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Bill Breakdown' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Billing Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'TimeDayBook' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Handler Diary Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Diary/Task Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Balances as at a Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Balances as at a Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Month End Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Balances as at a Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Fee Earner Summary' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Fee Earner Summary' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Fee Earner' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Fee Earner' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Client by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Worktype by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Department by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Department by Worktype by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Worktype by Fe by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Fe by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Fe by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Client by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Department by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Worktype by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Department by Worktype by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Worktype by Fee Earner by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt by Fee Earner' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt by Fee Earner' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Month End Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt by Fee Earner' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt by Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt by Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt by Client (Show Dates)' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt by Client (Show Dates)' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Case Diary Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Diary/Task Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Balances as at Entry Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt by Client (ShowDates) Client Summary' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt by Client (ShowDates) Client Summary' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'No Branching' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'WIP By FE' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports (Unbilled/WIP)' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'WIP by F/e Last Billed' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports (Unbilled/WIP)' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Billing Guide' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Statements' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Statements' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Recorder Utilisation' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'SupplierRemittance' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Other' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'KPI By Fee Earner' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'KPI Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'KPI By Department' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'KPI Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'KPI By Team' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'KPI Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'KPI by Firm' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'KPI Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued By Work type by Team by Fee for Month' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Department by Team by Fee for Month.' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'All Cases' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Case Detail Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Firm Case Analysis Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'PI Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Statute Of Limitations Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'PI Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Statute Of Limitations Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Statute of Limitations' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertaking List Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertakings by UndertakingTo' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertakings by Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertakings by Dept' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertakings by Dept by Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertakings by FE' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertakings by Matter' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertakings by Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Dormant Matters Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'PI Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Dormant Matters Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Exception Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Statute Of Limitations By FE By Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Statute of Limitations' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Statute Of Limitations By Dept' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Statute of Limitations' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Statute Of Limitations By Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Statute of Limitations' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Diary Time Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Diary/Task Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Case Summary Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Case Detail Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertakings Authorised By' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertakings By Status' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued By Department By FE By Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Department By FE By Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Ledger' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Ledger Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Ledger No Money' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Ledger Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go


DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Ledger WIP' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Ledger Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Activity List WIP' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Ledger Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Entry' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Entry' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Task by FE' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Negotiation Letter By FE (FNL)' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued By FE By Period Summary' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Estimated Fees By Est fees Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Ledger for Fe between dates' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Ledger Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Ledger by Matter by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Ledger Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Ledger By Matter By FE By Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Ledger Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Billed Time for an Individual Handler' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports (Billed)' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Billed Time By Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports (Billed)' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Billed Time' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports (Billed)' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Client by Worktype By Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Client by Worktype By Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Top WIP For Fe' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports (Unbilled/WIP)' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Category Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matters ReOpened' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Current Balance Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Exception Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Current Balance Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Balances By Matter Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Exception Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Balances By Matter Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'CaseDiary - Daily' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Diary/Task Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'CaseDiary - Weekly' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Diary/Task Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Creditors Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Creditors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Creditors Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Month End Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt Breakdown' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt Weekly' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt Weekly' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt By Dept' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt By Dept' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt By Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Aged Debt By Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Allocated Receipts' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Received Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Summary Report By Fee Earner' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Case Detail Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by FE By Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by FE By Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Charge Rates By FE By Matter' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Other' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client List' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Statement By Matter' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Outlay' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Digital Dictations By Author' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Dictation Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Digital Dictations By Handler' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Dictation Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Digital Dictations By Typist' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Dictation Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Est Fees Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'File Manager Report By Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'File Manager' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'File Manager Report by ItemCode' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'File Manager' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'File Manager Report by ItemType' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'File Manager' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Rec By FE By Client By Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Received Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Rec By FE By Client By Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Profit and Loss Budget By Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Profit And Loss Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Profit and Loss By Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Profit And Loss Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Profit and Loss Ledger' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Profit And Loss Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Profit and Loss Summary' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Profit And Loss Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Bills Profitibility Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Profitibility Report' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Bills Profitibility Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Profitibility By Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Profitibility Report' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Profitibility By Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Profitibility By Dept' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Profitibility Report' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Profitibility By Dept' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Debtors Ledger Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Debtors Ledger Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Draft Bills By Matter FE' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Billing Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Draft Bills By Matter FE' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Draft Bills By Billing FE' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Billing Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Draft Bills By Billing FE' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Expense Payments' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Invoiced OS Fees' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Summary Report By Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Case Detail Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matters With No Transactions' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Exception Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Transfer Costs By Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Transfer Costs By Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Trial Balance' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Trial Balance' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Month End Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Time Write Off By Dept' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'UnBilled Outlay Days' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports (Unbilled/WIP)' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'UnBilled Outlay Days' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'UnBilled Outlay Years' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports (Unbilled/WIP)' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'UnBilled Outlay Years' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Undertakings By Undertaking Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Undertakings' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Rec By Matter By Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Received Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Rec By Matter By Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Rec By Matter By Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Received Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Rec By Matter By Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List with No Account Values' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Case Analysis By FE' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Case Analysis By Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'List of Client Category' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Code List Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'List of Departments' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Code List Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'List of Fee Earners' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Code List Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'List of Handlers' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Code List Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'List of Nominal Ac Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Code List Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'List of Teams' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Code List Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'List of VAT Codes' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Code List Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'List of Work Types' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Code List Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Supplier List' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Other' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Supplier List' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Code List Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Partner' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Partner' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Your Ref' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Your Ref' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List Effectively Complete' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Outstanding Bills' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Billing Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Outstanding Bills' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Debtors Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Outstanding Bills' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Acc Debit Bal Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Exception Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Acc Debit Bal Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Month End Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Balance 90 Days Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Deposit Balances Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Outlay Balances as at a Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Office Account Credit Balances by Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Exception Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Office Account Credit Balances by Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Month End Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Office Account Credit Balances' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Exception Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Office Account Credit Balances' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Month End Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Ledger' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter Ledger Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Ledger' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Ledger By FE' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter Ledger Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Ledger By FE' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Income Projection Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Summary Report By Dept' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Case Detail Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Outstanding Cases By ActionCode' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Diary/Task Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Case Analysis By Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Case Analysis By Dept' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Case Analysis By Dept By Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Case Analysis By Work Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Billing Guide Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Billing Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Unbilled Time Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Time Reports (Unbilled/WIP)' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matters Not Billed' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Exception Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Nominal Ledger by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Nominal Ledger by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Nominal Ledger by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Nominal Ledger by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Ledger by Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter Ledger Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter Ledger by Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Action Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Diary/Task Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Debt Costing Ledger' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Client' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Dept' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List By Closed / Archived Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'BillingReport' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'New Cases Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Case Associates By Matter' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Case Detail Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Case Associates By Type' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Case Detail Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Phone Log Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Case Detail Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Client Balances Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Client Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Strong Room Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'File Manager' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Strong Room Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Case Detail Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List By Destroy Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Cheque Requisition' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'File Manager Report By Destroy Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'File Manager' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Workflow Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Diary/Task Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Bank Acc Register' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'EFT Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'EFT Case Assoc Bank Acc Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'EFT Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'EFT Client Bank Acc Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'EFT Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'EFT Completed Transactions Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'EFT Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'EFT OS Transactions Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'EFT Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'EFT Supplier Bank Acc Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'EFT Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Cheque Requisitions List' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'EFT Remittance' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'EFT Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List By Team' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'EFT Audit Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'EFT Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'System Reconciliation Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'System Reconciliation Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Month End Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Trial Balance by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Trial Balance by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Month End Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Trial Balance by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Trial Balance by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Month End Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Balance Sheet by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Balance Sheet by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Date' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Fees Issued Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Issued by Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Branch' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Matter List' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Matter List by Branch' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Nominal Account List' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'VAT CashReceipts Branch' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'VAT CashReceipts Branch Summary' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'VAT InvoiceBasis Branch' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'VAT InvoiceBasis Branch Summary' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Branching Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Balance Sheet' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Profit and Loss By Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Profit And Loss Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Fees Book By Period' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'UD Billing Report' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  FROM KaaS_CRReport WHERE [name] = 'Third Party Ledger' and[report_type] = 'A' 
SELECT @groupId =[groupid]  FROM KaaS_CRGroup WHERE [groupname] = 'Accounts Reports' 
IF NOT EXISTS(SELECT TOP 1 1 FROM[KaaS_CRReportGroup] WHERE [Reportid] = @reportId AND[groupid] = @groupId) AND @reportId IS NOT NULL AND @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]([Reportid], [groupid])VALUES(@reportId, @groupId)
End
Go

DECLARE @groupId INT; 
DECLARE @reportId INT; 
SELECT @reportId =[ReportId]  
       FROM KaaS_CRReport 
	   WHERE [name] = 'UD Billing Report' 
	     AND [report_type] = 'B' 
SELECT @groupId =[groupid]  
       FROM KaaS_CRGroup 
	   WHERE [groupname] = 'Billing Reports' 
IF NOT EXISTS
  (
  SELECT TOP 1 1 FROM[KaaS_CRReportGroup] 
         WHERE [Reportid] = @reportId 
		 AND   [groupid] = @groupId) 
		 AND   @reportId IS NOT NULL 
		 AND   @groupId IS NOT NULL
Begin 
INSERT INTO[dbo].[KaaS_CRReportGroup]
       (
	   [Reportid],
	   [groupid]
	   )
	   VALUES
	   (
	   @reportId,
	   @groupId
	   )
End
Go



--Update Script for CRParameter Value mismatch

IF EXISTS(SELECT TOP 1 1 FROM KaaS_CRParameter  WHERE [ParameterType] = 'N')
Begin
Update KaaS_CRParameter set ParameterType = 'Number' where ParameterType = 'N'
End
Go

IF EXISTS(SELECT TOP 1 1 FROM KaaS_CRParameter  WHERE [ParameterType] = 'D')
Begin
Update KaaS_CRParameter set ParameterType = 'Date' where ParameterType = 'D'
End
Go

IF EXISTS(SELECT TOP 1 1 FROM KaaS_CRParameter  WHERE [ParameterType] = 'T')
Begin
Update KaaS_CRParameter set ParameterType = 'Text' where ParameterType = 'T'
End
Go

IF EXISTS(SELECT TOP 1 1 FROM KaaS_CRParameter  WHERE [requiredfield] = '1')
Begin
Update KaaS_CRParameter set requiredfield = 'Yes' where requiredfield = '1'
End
Go

IF EXISTS(SELECT TOP 1 1 FROM KaaS_CRParameter  WHERE [userrequest] = '0')
Begin
Update KaaS_CRParameter set userrequest = 'No' where userrequest = '0'
End
Go

IF EXISTS(SELECT TOP 1 1 FROM KaaS_CRParameter  WHERE [controltype] = 'List')
Begin
UPDATE KaaS_CRParameter
   SET listoption = REPLACE(CAST(listoption as nVarchar(4000)), '|', ';')
       where controltype = 'List'
End
Go

IF EXISTS(SELECT TOP 1 1 FROM KaaS_CRParameter  WHERE [infile] = 'Fee Earner')
Begin
Update KaaS_CRParameter set infile = 'Fee Earners' where infile = 'Fee Earner'
End
Go

IF EXISTS(SELECT TOP 1 1 FROM KaaS_CRParameter  WHERE [infile] = 'Branch')
Begin
Update KaaS_CRParameter set infile = 'Branches' where infile = 'Branch'
End
Go

IF EXISTS(SELECT TOP 1 1 FROM KaaS_CRParameter  WHERE [defaultvalue] = '0' and infile !='')
Begin
update Kaas_CRParameter set defaultvalue = '' where defaultvalue = '0' and infile !=''
End
Go

IF EXISTS
  (SELECT TOP 1 1
     FROM SYS.[objects] SO
    WHERE SO.[name] = N'KaaS_CRParameter'
      AND SO.[type] = 'U') and 
   EXISTS
  (SELECT TOP 1 1 
     FROM KaaS_CRParameter  
	WHERE [defaultvalue] = 'GLO:Branch' 
	  AND [parametername] ='Branch')
BEGIN
update Kaas_CRParameter set defaultvalue = '' WHERE [defaultvalue] = 'GLO:Branch' AND [parametername] ='Branch'
END
Go

--Update infile value from Supplier to Suppliers
IF EXISTS
  (SELECT TOP 1 1
     FROM SYS.[objects] SO
    WHERE SO.[name] = N'KaaS_CRParameter'
      AND SO.[type] = 'U') and 
   EXISTS
  (SELECT TOP 1 1 
     FROM KaaS_CRParameter  
	WHERE [Infile] = 'Supplier')
BEGIN
update Kaas_CRParameter 
set [Infile] = 'Suppliers' 
WHERE [Infile] = 'Supplier'
END
Go

--UPDATE Sequ nO to 1 when it is 0
IF EXISTS(SELECT TOP 1 1 FROM [dbo].[KaaS_CRParameter] WHERE [Seqno] = 0 )
BEGIN
UPDATE [dbo].[KaaS_CRParameter] SET [Seqno] = 1 WHERE [Seqno] = 0
END
GO

--UPDATE name from Cheque to payment	
IF EXISTS(SELECT TOP 1 1 FROM [dbo].[Kaas_CrReport] WHERE [Name] = 'Cheque Requisition' )
BEGIN
UPDATE [dbo].[Kaas_CrReport] 
       SET   [Name] = 'Payment Request' 
	   WHERE [Name] = 'Cheque Requisition'
END
GO

IF EXISTS(SELECT TOP 1 1 FROM [dbo].[Kaas_CrReport] WHERE [Name] = 'Cheque Requisitions List' )
BEGIN
UPDATE [dbo].[Kaas_CrReport] 
       SET   [Name] = 'Payment Request List' 
	   WHERE [Name] = 'Cheque Requisitions List'
END
GO


IF EXISTS(SELECT TOP 1 1 FROM [dbo].[Kaas_CrParameter] WHERE [UserPrompt] = 'Enter the Cheque Requisition Number' )
BEGIN
UPDATE [dbo].[Kaas_CrParameter] 
       SET   [UserPrompt] = 'Enter the Payment Request Number' 
	   WHERE [UserPrompt] = 'Enter the Cheque Requisition Number'
END
GO

DECLARE @reportId INT; 
SELECT @reportId =[ReportId] 
       FROM KaaS_CRReport 
	   WHERE 
	   [name] = 'Fees Rec By Matter By Date' 
	   AND
	   [report_type] = 'A' 
IF EXISTS
   (
    SELECT TOP 1 1 FROM 
	       [dbo].[Kaas_CrParameter] 
		   WHERE 
		   InFile = 'Branches' 
		   AND
		   [ReportId] = @reportId
		   AND 
		   [RequiredField] = 'Yes'
   )
BEGIN
    UPDATE [dbo].[Kaas_CrParameter] 
       SET   [RequiredField] = 'No' 
	   WHERE 
	         InFile = 'Branches' 
		     AND
		     [ReportId] = @reportId
END
GO

DECLARE @reportId INT; 
SELECT @reportId =[ReportId] 
       FROM KaaS_CRReport 
	   WHERE 
	   [name] = 'Fees Rec By Matter By Period' 
	   AND
	   [report_type] = 'A' 
IF EXISTS
   (
    SELECT TOP 1 1 FROM 
	       [dbo].[Kaas_CrParameter] 
		   WHERE 
		   InFile = 'Branches'
		   AND
		   [ReportId] = @reportId
		   AND 
		   [RequiredField] = 'Yes'
   )
BEGIN
    UPDATE [dbo].[Kaas_CrParameter] 
       SET   [RequiredField] = 'No' 
	   WHERE 
	         InFile = 'Branches' 
		     AND
		     [ReportId] = @reportId
END
GO




