The following function gives Warning in SSDT 14.0.60923.0 SQL71502: Function: [dbo].[fn_CheckPolicy] has an unresolved reference to object [dbo].[Users].[d] incorrectly in Visual Studio 2015.
Is there a way around this or is it a bug in SSDT?
CREATE FUNCTION [dbo].[fn_CheckPolicy] (@NameIdentifier nvarchar(128),
@Id uniqueidentifier)
RETURNS @returntable TABLE (
[Id] uniqueidentifier,
[Acl] int )
AS
BEGIN
WITH cte
AS (SELECT 1 AS [Level],
JSON_VALUE(d.[value], '$.id') AS 'Id',
JSON_VALUE(d.[value], '$.acl') AS 'acl',
JSON_VALUE(d.[value], '$.type') AS 'type',
JSON_QUERY(d.[value], '$.s') AS 'data'
FROM [dbo].[Users] u
CROSS apply OPENJSON(JSON_QUERY(u.[Policy], '$.c')) d
WHERE u.[NameIdentifier] = @nameIdentifier
UNION ALL
SELECT [Level] + 1,
ISNULL(JSON_VALUE(d.[value], '$.id'), '00000000-0000-0000-0000-000000000000'),
JSON_VALUE(d.[value], '$.acl'),
JSON_VALUE(d.[value], '$.type') 'type',
JSON_QUERY(d.[value], '$.a') 'data'
FROM cte
CROSS apply OPENJSON(JSON_QUERY([data], '$')) d)
INSERT INTO @returnTable
SELECT [Id],
CONVERT(int, CONVERT(varbinary, [Acl], 1))
FROM cte
WHERE [Id] = @id
IF @@ROWCOUNT = 0
INSERT INTO @returntable
([Id],[Acl])
VALUES (@id,'0xff')
RETURN
END
That looks like a bug with the handling of OPENJSON in SSDT. There were some bug fixes in this area in recent versions of SSDT, but it appears that this is another issue. Could you please file a Connect bug for this at https://connect.microsoft.com/SQLServer/feedback/CreateFeedback.aspx using the category "Developer Tools (SSDT, BIDS, etc.)"? Thank you!