Skip to content

Commit 851b623

Browse files
Merge pull request #1072 from TechnologyEnhancedLearning/Develop/Fixes/TD-5407-SQL-Exception
TD-5407: Created new SP to fix the SQL exception
2 parents 743ba20 + 76178a2 commit 851b623

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<Folder Include="Functions\Resources" />
101101
<Folder Include="Triggers" />
102102
<Folder Include="Triggers\external" />
103+
<Folder Include="Stored Procedures\External" />
103104
</ItemGroup>
104105
<ItemGroup>
105106
<None Include="Scripts\learningHub_Data.sql" />
@@ -537,6 +538,7 @@
537538
<None Include="Scripts\Post-Deploy\Scripts\AddDigitalLearningSolutionsExternalSystem.sql" />
538539
<Build Include="Stored Procedures\Activity\GetAssessmentActivityCompletionPercentage.sql" />
539540
<Build Include="Tables\Hub\PasswordResetRequests.sql" />
541+
<Build Include="Stored Procedures\External\ExternalSystemUserCreate.sql" />
540542
</ItemGroup>
541543
<ItemGroup>
542544
<None Include="Scripts\Pre-Deploy\Scripts\Card5766_AuthorTableChanges.PreDeployment.sql" />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-------------------------------------------------------------------------------
2+
-- Author Swapnamol Abraham
3+
-- Created 07-04-2025
4+
-- Purpose Creates a External System user
5+
--
6+
-- Modification History
7+
--
8+
-- 07-04-2025 SA Initial Revision
9+
-------------------------------------------------------------------------------
10+
CREATE PROCEDURE [external].[ExternalSystemUserCreate]
11+
(
12+
@userId int,
13+
@externalSystemId int,
14+
@amendUserId INT,
15+
@UserTimezoneOffset int = NULL
16+
)
17+
18+
AS
19+
20+
BEGIN
21+
BEGIN TRY
22+
BEGIN TRAN
23+
DECLARE @AmendDate datetimeoffset(7) = ISNULL(TODATETIMEOFFSET(DATEADD(mi, @UserTimezoneOffset, GETUTCDATE()), @UserTimezoneOffset), SYSDATETIMEOFFSET())
24+
-- Insert into ExternalSystemUser table
25+
INSERT INTO [external].[ExternalSystemUser]
26+
(UserId, ExternalSystemId, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate)
27+
SELECT @userId, @externalSystemId, 0, @amendUserId, @amendDate, @amendUserId, @amendDate
28+
29+
COMMIT
30+
END TRY
31+
BEGIN CATCH
32+
DECLARE @ErrorMessage NVARCHAR(4000);
33+
DECLARE @ErrorSeverity INT;
34+
DECLARE @ErrorState INT;
35+
36+
SELECT
37+
@ErrorMessage = ERROR_MESSAGE(),
38+
@ErrorSeverity = ERROR_SEVERITY(),
39+
@ErrorState = ERROR_STATE();
40+
41+
IF @@TRANCOUNT > 0
42+
ROLLBACK TRAN;
43+
44+
RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState);
45+
46+
END CATCH
47+
END
48+
GO

0 commit comments

Comments
 (0)