Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Last active October 19, 2024 18:25
Show Gist options
  • Save wullemsb/77e69acf7156137ecdd1d3349a9f481c to your computer and use it in GitHub Desktop.
Save wullemsb/77e69acf7156137ecdd1d3349a9f481c to your computer and use it in GitHub Desktop.
CREATE PROCEDURE [dbo].[READBYKEYS] (
@list NVARCHAR(MAX),
@user NVARCHAR(50),
)
AS
BEGIN
SET NOCOUNT ON;
-- Temporary table to hold IDs from the list
DECLARE @hastable TABLE (Id BIGINT);
-- Split the input list and insert into the temporary table
INSERT INTO @hastable (Id)
SELECT TRY_CAST(value AS BIGINT)
FROM STRING_SPLIT(@list, ',')
WHERE TRY_CAST(value AS BIGINT) IS NOT NULL;
//We should log every attempt to query this datasource
INSERT INTO AUDIT_LOG (@user, @list)
SELECT RR_DATA.ID, NR_RR
FROM RR_DATA
INNER JOIN @hastable ha ON RR_DATA.ID = ha.Id;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment