feat: Add Admin Groups Management Module
- Introduced a new module for managing user groups (`usrgrp`) in the administration interface. - Implemented CRUD operations for user groups: list, create, rename, and delete. - Added authorization checks to ensure only users with appropriate permissions can manage groups. - Created corresponding frontend JavaScript and SCSS files for the new module. - Updated documentation to reflect the new group management functionality and its authorization model. - Added SQL stored procedures for group management operations. - Established a new login script for database access, ensuring proper security practices.
This commit is contained in:
@@ -15,7 +15,7 @@ CREATE FUNCTION [dbo].[fis_admin_getUserAccountList]
|
||||
, @usergroup_id varchar(5)
|
||||
, @include_nonmembers as bit
|
||||
)
|
||||
RETURNS @RET TABLE ( [useraccount_id] varchar(5), [auth] smallint, [name] nvarchar(100) null, [firstname] nvarchar(100) null, [title] varchar(50) NULL, [gender] varchar(1), [email] varchar(255) NULL, [mobile] varchar(50) null, [functions] varchar(1000), [language] varchar(2), [disabled] bit, [nologin] bit, [member] bit, [order] int)
|
||||
RETURNS @RET TABLE ( [useraccount_id] varchar(5), [auth] smallint, [name] nvarchar(100) null, [firstname] nvarchar(100) null, [title] varchar(50) NULL, [gender] varchar(1), [email] varchar(255) NULL, [mobile] varchar(50) null, [functions] varchar(1000), [language] varchar(2), [disabled] bit, [nologin] bit, [member] bit, [groups] nvarchar(max) NULL, [order] int)
|
||||
AS
|
||||
BEGIN
|
||||
DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount);
|
||||
@@ -49,6 +49,12 @@ BEGIN
|
||||
,'disabled' = CASE WHEN ua.[DateDisabled] IS NULL THEN 0 ELSE 1 END
|
||||
,'nologin' = CAST(CASE WHEN ua.[password_enc] is null THEN 1 WHEN ISNULL(CAST(DECRYPTBYKEY(ua.[password_enc]) as varchar(20)),'') = '' THEN 1 ELSE 0 END as bit)
|
||||
,'member' = CASE WHEN @usergroup_id IS NULL THEN NULL WHEN sgm.[useraccount_id] is not null THEN 1 ELSE 0 END
|
||||
,'groups' = (SELECT STRING_AGG(CAST(DECRYPTBYKEY(ug.[name_enc]) as nvarchar(max)), ', ') WITHIN GROUP (ORDER BY CAST(DECRYPTBYKEY(ug.[name_enc]) as nvarchar(255)))
|
||||
FROM [dbo].[fis_usergroups_members] as ugm
|
||||
JOIN [dbo].[fis_usergroups] as ug ON ug.[usergroup_id] = ugm.[usergroup_id]
|
||||
WHERE ugm.[useraccount_id] = ua.[useraccount_id]
|
||||
AND ugm.[DateDeleted] is null
|
||||
AND ug.[DateDeleted] is null) /* csv of all active group memberships, alphabetically */
|
||||
,'order' = ROW_NUMBER() OVER (ORDER BY CAST(DECRYPTBYKEY(ua.[name_enc]) as nvarchar(255)))
|
||||
FROM [dbo].[fis_useraccounts] as ua
|
||||
LEFT JOIN SelectedGroupMembers as sgm on sgm.[useraccount_id] = ua.[useraccount_id]
|
||||
|
||||
@@ -11,8 +11,9 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
DECLARE @utcnow datetime = GETUTCDATE();
|
||||
DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount);
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM [dbo].[fis_usergroups_members] WHERE [usergroup_id] = @usergroup_id AND [useraccount_id] = @useraccount_id and [DateDeleted] is null)
|
||||
IF @auth > 1 AND NOT EXISTS (SELECT * FROM [dbo].[fis_usergroups_members] WHERE [usergroup_id] = @usergroup_id AND [useraccount_id] = @useraccount_id and [DateDeleted] is null)
|
||||
BEGIN
|
||||
|
||||
INSERT INTO [dbo].[fis_usergroups_members]
|
||||
|
||||
@@ -12,8 +12,9 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
DECLARE @utcnow datetime = GETUTCDATE();
|
||||
DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount);
|
||||
|
||||
IF EXISTS (SELECT * FROM [dbo].[fis_usergroups] WHERE [usergroup_id] = @usergroup_id and [DateDeleted] is null)
|
||||
IF @auth > 1 AND EXISTS (SELECT * FROM [dbo].[fis_usergroups] WHERE [usergroup_id] = @usergroup_id and [DateDeleted] is null)
|
||||
BEGIN
|
||||
|
||||
UPDATE [dbo].[fis_usergroups]
|
||||
|
||||
@@ -12,8 +12,9 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
DECLARE @utcnow datetime = GETUTCDATE();
|
||||
DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount);
|
||||
|
||||
IF EXISTS (SELECT * FROM [dbo].[fis_usergroups_members] WHERE [usergroup_id] = @usergroup_id AND [useraccount_id] = @useraccount_id and [DateDeleted] is null)
|
||||
IF @auth > 1 AND EXISTS (SELECT * FROM [dbo].[fis_usergroups_members] WHERE [usergroup_id] = @usergroup_id AND [useraccount_id] = @useraccount_id and [DateDeleted] is null)
|
||||
BEGIN
|
||||
|
||||
UPDATE [dbo].[fis_usergroups_members]
|
||||
|
||||
@@ -11,12 +11,17 @@ CREATE PROCEDURE [dbo].[mfr__updt__#customvalues]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__#customvalues];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM [' + @tblname + ']';
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
--WITH tmp as (
|
||||
-- SELECT *, ROW_NUMBER() OVER (PARTITION BY [id],[Property] ORDER BY [version] DESC) as '#' FROM @tmp
|
||||
--), SOURCE as (
|
||||
@@ -43,4 +48,15 @@ BEGIN
|
||||
,SOURCE.[Property]
|
||||
,SOURCE.[Meta]
|
||||
,SOURCE.[Value]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,17 @@ CREATE PROCEDURE [dbo].[mfr__updt__#locations]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__#locations];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM [' + @tblname + ']';
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
WITH tmp as (
|
||||
SELECT *, ROW_NUMBER() OVER (PARTITION BY [id],[Property] ORDER BY [version] DESC) as '#' FROM @tmp
|
||||
), SOURCE as (
|
||||
@@ -64,4 +69,15 @@ BEGIN
|
||||
,SOURCE.[Longitude]
|
||||
,SOURCE.[Latitude]
|
||||
,SOURCE.[IsValidLocation]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__*PartnerSet]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__*PartnerSet];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM [' + @tblname + ']';
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__*PartnerSet] as TARGET
|
||||
USING @tmp as SOURCE ON
|
||||
@@ -40,4 +44,15 @@ BEGIN
|
||||
,SOURCE.[PartnerType]
|
||||
,SOURCE.[PartnerId]
|
||||
,SOURCE.[EntityId]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__appointments]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__appointments];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__appointments] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -63,4 +67,15 @@ BEGIN
|
||||
,SOURCE.[ServiceRequestId]
|
||||
,SOURCE.[ContactId]
|
||||
,SOURCE.[Note]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__attachments]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__attachments];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__attachments] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -36,4 +40,15 @@ BEGIN
|
||||
,SOURCE.[Version]
|
||||
,SOURCE.[URI]
|
||||
,SOURCE.[StepId]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__comments]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__comments];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__comments] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -45,4 +49,15 @@ BEGIN
|
||||
,SOURCE.[ServiceRequestId]
|
||||
,SOURCE.[CompanyId]
|
||||
,SOURCE.[Content]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,6 +10,9 @@ CREATE PROCEDURE [dbo].[mfr__updt__companies]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @now datetime = GETUTCDATE();
|
||||
DECLARE @tmp [dbo].[mfr__tt__companies];
|
||||
@@ -17,6 +20,8 @@ BEGIN
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
IF @referencetable = 'mfr__companies'
|
||||
BEGIN
|
||||
DELETE p
|
||||
@@ -99,4 +104,15 @@ BEGIN
|
||||
,SOURCE.[DateModified]
|
||||
,SOURCE.[CustomValues]
|
||||
,SOURCE.[MainContactId]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__contacts]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__contacts];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__contacts] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -75,4 +79,15 @@ BEGIN
|
||||
,SOURCE.[ExternalId]
|
||||
,SOURCE.[Gender]
|
||||
,SOURCE.[UserId]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__costcenters]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__costcenters];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__costcenters] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -33,4 +37,15 @@ BEGIN
|
||||
(SOURCE.[Id]
|
||||
,SOURCE.[Version]
|
||||
,SOURCE.[Name]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__documents]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__documents];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__documents] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -75,4 +79,15 @@ BEGIN
|
||||
,SOURCE.[HTMLCode]
|
||||
,SOURCE.[ServiceRequestId]
|
||||
,SOURCE.[Note]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__invoices]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__invoices];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__invoices] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -80,4 +84,15 @@ BEGIN
|
||||
,SOURCE.[InvoiceState]
|
||||
,SOURCE.[Note]
|
||||
,newid());
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__items]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__items];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__items] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -96,4 +100,15 @@ BEGIN
|
||||
,SOURCE.[CreatorId]
|
||||
,SOURCE.[UnitId]
|
||||
,SOURCE.[UnitString]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__itemtypes]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__itemtypes];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__itemtypes] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -87,4 +91,15 @@ BEGIN
|
||||
,SOURCE.[IsWarehouse]
|
||||
,SOURCE.[UnitId]
|
||||
,SOURCE.[UnitString]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__itemunits]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__itemunits];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__itemunits] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -33,4 +37,15 @@ BEGIN
|
||||
(SOURCE.[Id]
|
||||
,SOURCE.[Version]
|
||||
,SOURCE.[Name]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__products]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__products];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__products] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -48,4 +52,15 @@ BEGIN
|
||||
,SOURCE.[DateModified]
|
||||
,SOURCE.[MappingId]
|
||||
,SOURCE.[CustomValueStepTemplateId]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__qualifications]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__qualifications];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__qualifications] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -33,4 +37,15 @@ BEGIN
|
||||
(SOURCE.[Id]
|
||||
,SOURCE.[Version]
|
||||
,SOURCE.[Name]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__reports]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__reports];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__reports] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -72,4 +76,15 @@ BEGIN
|
||||
,SOURCE.[IsInvoice]
|
||||
,SOURCE.[IsCanceled]
|
||||
,SOURCE.[CustomValues]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,6 +10,9 @@ CREATE PROCEDURE [dbo].[mfr__updt__serviceobjects]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @now datetime = GETUTCDATE();
|
||||
DECLARE @tmp [dbo].[mfr__tt__serviceobjects];
|
||||
@@ -17,6 +20,8 @@ BEGIN
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
IF @referencetable = 'mfr__serviceobjects'
|
||||
BEGIN
|
||||
DELETE p
|
||||
@@ -90,4 +95,15 @@ BEGIN
|
||||
,SOURCE.[ParentServiceObjectId]
|
||||
,SOURCE.[CompanyId]
|
||||
,SOURCE.[ProductId]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,6 +10,7 @@ CREATE PROCEDURE [dbo].[mfr__updt__servicerequests]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
@@ -151,20 +152,11 @@ BEGIN
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
INSERT INTO dbo.[fds__admin_dberrors]
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
-- Transaction uncommittable
|
||||
--IF (XACT_STATE()) = -1
|
||||
ROLLBACK TRANSACTION;
|
||||
|
||||
-- Transaction committable
|
||||
--IF (XACT_STATE()) = 1
|
||||
--COMMIT TRANSACTION;
|
||||
|
||||
|
||||
DECLARE @Message varchar(MAX) = ERROR_MESSAGE(), @Severity int = ERROR_SEVERITY(), @State smallint = ERROR_STATE();
|
||||
RAISERROR (@Message, @Severity, @State);
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__steplisttemplateinstances]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__steplisttemplateinstances];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__steplisttemplateinstances] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -39,4 +43,15 @@ BEGIN
|
||||
,SOURCE.[Name]
|
||||
,SOURCE.[ServiceRequestId]
|
||||
,SOURCE.[TemplateId]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,15 +10,19 @@ CREATE PROCEDURE [dbo].[mfr__updt__steplisttemplates]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @now datetime = GETUTCDATE();
|
||||
DECLARE @tmp [dbo].[mfr__tt__steplisttemplates];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
IF @referencetable = 'mfr__steplisttemplates'
|
||||
BEGIN
|
||||
DELETE stp
|
||||
@@ -56,4 +60,15 @@ BEGIN
|
||||
,SOURCE.[DateModified]
|
||||
,SOURCE.[IsReleased]
|
||||
,SOURCE.[IsDurable]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,6 +10,9 @@ CREATE PROCEDURE [dbo].[mfr__updt__steps]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @now datetime = GETUTCDATE();
|
||||
DECLARE @tmp [dbo].[mfr__tt__steps];
|
||||
@@ -53,6 +56,7 @@ BEGIN
|
||||
END
|
||||
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__steps] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -146,4 +150,15 @@ BEGIN
|
||||
-- ,[DateDeleted] = @now
|
||||
-- FROM @ARCHIVE
|
||||
-- WHERE [ActionType] IN ( 'DELETE', 'UPDATE' );
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__stockmovements]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__stockmovements];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__stockmovements] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -72,4 +76,15 @@ BEGIN
|
||||
,SOURCE.[TargetDate]
|
||||
,SOURCE.[CreatedById]
|
||||
,SOURCE.[ConfirmedById]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,17 @@ CREATE PROCEDURE [dbo].[mfr__updt__tags]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__tags];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
WITH tmp as (
|
||||
SELECT *, ROW_NUMBER() OVER (PARTITION BY [id] ORDER BY [version] DESC) as '#' FROM @tmp
|
||||
), SOURCE as (
|
||||
@@ -43,4 +48,15 @@ BEGIN
|
||||
,SOURCE.[Name]
|
||||
,SOURCE.[ColorDefinition]
|
||||
,SOURCE.[Type]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,12 +10,16 @@ CREATE PROCEDURE [dbo].[mfr__updt__timeevents]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
DECLARE @tmp [dbo].[mfr__tt__timeevents];
|
||||
|
||||
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
||||
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
MERGE [dbo].[mfr__timeevents] as TARGET
|
||||
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
||||
@@ -63,4 +67,15 @@ BEGIN
|
||||
,SOURCE.[ContactId]
|
||||
,SOURCE.[ServiceRequestId]
|
||||
,SOURCE.[Description]);
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
@@ -10,6 +10,7 @@ CREATE PROCEDURE [dbo].[mfr__updt__users]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
BEGIN TRY
|
||||
|
||||
@@ -90,20 +91,11 @@ BEGIN
|
||||
COMMIT TRANSACTION;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
INSERT INTO dbo.[fds__admin_dberrors]
|
||||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
||||
|
||||
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
||||
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
||||
|
||||
-- Transaction uncommittable
|
||||
--IF (XACT_STATE()) = -1
|
||||
ROLLBACK TRANSACTION;
|
||||
|
||||
-- Transaction committable
|
||||
--IF (XACT_STATE()) = 1
|
||||
--COMMIT TRANSACTION;
|
||||
|
||||
|
||||
DECLARE @Message varchar(MAX) = ERROR_MESSAGE(), @Severity int = ERROR_SEVERITY(), @State smallint = ERROR_STATE();
|
||||
RAISERROR (@Message, @Severity, @State);
|
||||
|
||||
THROW;
|
||||
END CATCH;
|
||||
END
|
||||
Reference in New Issue
Block a user