﻿

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[ott_jcsv_containskey]
(
	@groupcode varchar(10)
	,@text varchar(4000)
)
RETURNS bit
AS
BEGIN
	DECLARE @RET bit;
	DECLARE @textinput varchar(4000) = REPLACE(ISNULL(@text, ''), ' ', '');

	IF (@textinput = '' OR @textinput = '{}')
		BEGIN
			SET @RET = 0;
		END
	ELSE
		BEGIN

			-- Will be true 
			-- if any of the fragments exist in the list of text-items
	
			DECLARE @Pattern varchar(20) = '%"' + @groupcode + '":"%';
			DECLARE @P0 int = PATINDEX(@pattern, @textinput);

			SET @RET = Case WHEN @P0 = 0 THEN 0 ELSE 1 END;

		END

	RETURN @RET;

END