Files
Fuchs_Intranet/Fuchs_Database/dbo/Stored Procedures/mfr__updt__#locations.sql
T
Stefan 8bcec409c5 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.
2026-09-16 09:35:31 +02:00

83 lines
2.2 KiB
Transact-SQL

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[mfr__updt__#locations]
@tblname as nvarchar(50)
, @referencetable nvarchar(50)
, @tgtid bigint
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 (
SELECT * FROM tmp WHERE [#] = 1
)
MERGE [dbo].[mfr__#locations] as TARGET
USING SOURCE ON TARGET.[Id] = SOURCE.[Id] AND TARGET.[Property] = SOURCE.[Property]
WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN
UPDATE
SET [Id] = SOURCE.[Id]
,[EntityId] = SOURCE.[EntityId]
,[Property] = SOURCE.[Property]
,[Version] = SOURCE.[Version]
,[AddressString] = SOURCE.[AddressString]
,[Postal] = SOURCE.[Postal]
,[City] = SOURCE.[City]
,[State] = SOURCE.[State]
,[Country] = SOURCE.[Country]
,[Longitude] = SOURCE.[Longitude]
,[Latitude] = SOURCE.[Latitude]
,[IsValidLocation] = SOURCE.[IsValidLocation]
WHEN NOT MATCHED BY TARGET THEN
INSERT
( [Id]
,[EntityId]
,[Property]
,[Version]
,[AddressString]
,[Postal]
,[City]
,[State]
,[Country]
,[Longitude]
,[Latitude]
,[IsValidLocation])
VALUES
(SOURCE.[Id]
,SOURCE.[EntityId]
,SOURCE.[Property]
,SOURCE.[Version]
,SOURCE.[AddressString]
,SOURCE.[Postal]
,SOURCE.[City]
,SOURCE.[State]
,SOURCE.[Country]
,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