USE [ArizonaREP];
GO

--#region fn_StringSplit()
CREATE OR ALTER FUNCTION [dbo].[fnSplitString] (
    @string    NVARCHAR(MAX),
    @delimiter CHAR(1)
)
RETURNS @output TABLE (
    [value] NVARCHAR(MAX)
)
BEGIN
    DECLARE @start INT,
            @end   INT;
    SELECT @start = 1,
           @end   = CHARINDEX(@delimiter, @string);
    WHILE @start < LEN(@string) + 1
    BEGIN
        IF @end = 0
            SET @end = LEN(@string) + 1;

        INSERT INTO @output (
            [value]
        )
        VALUES (
            SUBSTRING(@string, @start, @end - @start)
        );
        SET @start = @end + 1;
        SET @end = CHARINDEX(@delimiter, @string, @start);

    END;
    RETURN;
END;
--#endregion fn_StringSplit()
GO

DECLARE @input VARCHAR(MAX)
    = 'C73898FF-5503-4565-BF1B-0EB6B9C931C3,7827AE66-6A0A-4CC9-A285-EF9269FC720D,3568B542-C543-4392-A370-88C9CD64F8C8,665A9FF2-2C31-4CFF-B341-6B657AAAB801,1B839554-509A-4CFC-802A-24F3094615D7,A8F72DC3-3398-47FE-80FD-31B316B4963D,A40AAEB1-1EDB-445F-B5E6-34BBED9640D8,E51A1139-9B7A-422F-8B54-ECB505DDB8E3,5B59C63B-6F9F-4C27-B29E-FFE75E952249,36C6EB7C-9E6E-40BC-8F95-FAB7C24667A0,3F358729-17EA-46F5-89F8-3D479025B9F9,BDF0B7BA-B6AD-4C85-9D61-C0BCFAC583AA,51F2424E-F612-4C2B-8BC5-9CB4A99F5A46,2CF05930-C477-44F9-9595-4B78F696CFFD,04CDF0CC-0241-41EC-969F-FA0749794F46,72433873-0DC5-46D0-9C06-BD568D31C7AE,8EC41453-AB8D-4F16-859B-E2EDBD2DBB2F,C390DC70-26FC-46E7-9080-45C9BE1D6889,E0BD4EAF-4CC0-42D1-ADAB-4D7471A68283,B118BE7E-563D-4316-B7CC-1F01CEE3B039,C9B34504-166C-48C4-822D-617C51220748,F586CCCA-23A2-40A0-84B7-436779762DC4,2D0C6359-A098-428E-A6AE-DBBBABF043AE,9A619595-02B6-44A6-B82B-F679D8724874,DDDE8312-124C-4B58-904E-5048A04ED389,37EF5C4A-EA7D-4EBA-8953-95658CFF0BA5,BD035A75-BE42-43E7-A9AC-23F33A81A5C5,635B9C48-38B7-405F-89CF-09F1327D4071,C325545D-2B8C-4CB7-A41D-B0CB421EE844,09A57484-66B9-43CA-B9D3-3E4ED363C730,048DD6ED-1D33-4741-AF28-897B6FBE27ED,7E8488A5-A56F-47D8-B393-7A0B43776A68,5E2DA8D5-36DD-4F07-8C16-3DFF1D21F023,B5E69008-2989-4CFA-86D4-946E591170D8,DC613FD4-A0AA-4D17-ADDF-7D26F3EEAC4F,CA0B8803-EFE4-44C9-A664-5B4123EAE7EE,8CF9A86D-E257-4213-B82E-A6AFB42C5E0B,D76A5BC9-6F5C-4124-A3FF-055128763D43,72440A44-6567-4695-910F-3D0977E114E9,E78B77D9-9CC3-417B-8E79-FB35324EB2D6,F19D17F5-F5ED-4A12-BC03-3A319CA8B8E2,2B00E466-CEA3-4AC6-BF69-E46534E8CE52,798D1622-811E-436E-BDB5-38635507BDC0,029E540F-8143-49A5-A047-7E623B387730,4367A715-5BFB-4239-B64E-D14EA6206130,15AFCAB3-AB1A-44B8-8772-A70B117339CE,04FF167C-6FE9-41D7-9015-50AD4BE27FF4,7CB284A9-F767-41F6-9AEC-3FC94FAE1EB4,F94A54D5-7DF0-43EA-A060-470CA7F3EFAC,68D94F61-6F14-4961-9A6F-4B8DBAE59799,C64326DA-EDF8-4FF9-8CE0-F0E380A28A1C,697E54FB-8D7B-4555-AF4F-38443078A01D,198B8239-D9F0-4148-A33F-C472BD3791AF,C7747A95-0CB0-4507-A35E-3C90C4DCA928,CEE05E37-705E-4BEE-BD9D-64CA38B8CC41,58B7055E-446C-4418-8917-CE2F3F286977,1A45D7AF-5CB5-420B-97E2-65831FB0B1FE,E4347572-64D3-484F-85EE-903D7DA8E58B,1C5B9754-14CD-4C81-AE75-FD095F089564,7DDC7190-7B92-427A-87C4-8E4B47348236,5BC2E239-C984-4D93-BEDE-1AEA1AD75016,81CDA684-3B50-4B09-A982-84F7F9640B18,2BF35438-E23F-4288-B187-237E6B9A8557,0F3EA17E-F334-4A3B-A8D4-8DC0FF91BCE2,A89197EB-013D-4A2D-898F-AE79191799C7,0BBBCD77-3333-4FF8-B06E-2547D6EC1FAD,0B4E5C88-3AB3-4925-9551-89602C024E0E,4ADAA89F-0409-459E-AE07-0A675BE9426D,8C5340AC-4119-47C0-B06F-F03A52B1B6BF,6EC0ED06-AE8A-4144-A638-1D19CB796EC0,832DC701-F925-47D3-8E64-A068EE6C36AB,39904FFA-ACA7-4E30-A68B-06C4416D3888,6736CE51-FF16-4C23-ABCB-BB85096A08B7,E158BEAB-7D32-4242-BCC9-3EE3E357CF4F,1042E15B-9E87-4F92-AB31-54FA46643F2C,C1ADDF37-C581-473E-B757-37C7F6E85A77,2D93F824-FEE3-4175-9F40-02846EBCCA0E,FB1B5495-6E45-4D3B-8FAC-98CAD37718FF,D27F9EF5-5D45-4A16-82BC-99DA574286EA,B79AE10A-0CB5-4CBA-BB18-2DE32C43077B,3EB0947C-2CF7-4272-B46A-00CB35ECFF9D,069D4B6B-D356-47D3-9FF3-ECC53BD6CC62,D7E8F35B-A2E7-4562-9F4F-0119EB068FBD,D429C601-EE85-440F-AC66-11BAACC11F69,5F6978C3-C8F0-46AA-9222-74746E103458,09611BCB-26D6-4D9D-972E-08759AF0DA30,7CF6034E-E4E3-4E82-AA27-185972146F41,52DECBE0-78DC-4393-9C09-069FD324165F,052A31BB-2E57-480A-BF49-1524631114E6,8B03ADF6-BBC8-49E9-9B15-AAFD915ADD83,B7C190CA-12B1-4B7B-9EBF-D9D208CF364C,82855646-59C3-461E-8BBF-CEDBE0EA235C,94C980B9-FC43-4EC2-BF7C-77C00AD44CE1,51AB8015-B7BA-44DB-888B-F75D797B03EB,87696D53-AE00-40B6-897A-0B9E89119A97,4BEF71D1-BD1A-4F39-8C13-31DCC56FC51F,96DC1B07-ABA3-4560-B844-D76FFAD70DFB,EB435CF7-B5E3-4A5F-A348-B8F0E06FDC9D,D0A09608-F66C-43F9-AF8A-75AEEE27358A,9E9D0D81-4733-4E98-AE0D-B5D3D62ECE17,173DB54C-9615-418F-AC50-236733BF1A5E';

WITH [cteValues] AS (
    --transform input values in a table
    SELECT [value] AS [address_guid]
    FROM [dbo].fnSplitString(@input, ',')
)

SELECT 
    v.[address_guid]
    , dbo.[aps_fn_Is_Address_Authorization_Granted](v.[address_guid],1,null) AS isGranted
FROM [cteValues] v