一种性能不佳但可行的方法是使用 varchar(MAX) 并以逗号分隔的方式获取 UID。
然后你可以对它做一个 LIKE :
CREATE FUNCTION [dbo].[tfu_RPT_SEL_Gebaeude]
(
--@in_mandant varchar(3)
--,@in_sprache varchar(2)
--,@in_groups varchar(8000)
--,@in_stichtag varchar(50)
@Standortkategorie varchar(MAX)
,@Standort varchar(MAX)
)
RETURNS table
AS
RETURN
(
SELECT '00000000-0000-0000-0000-000000000001' AS RPT_FID_SK_UID, '00000000-0000-0000-0000-000000000000' AS RPT_FID_SO_UID, '00000000-0000-0000-0000-000000000000' AS RPT_UID, 'Ohne' AS RPT_Name, 999999999 AS RPT_Sort
UNION
SELECT DISTINCT
ISNULL(T_AP_Gebaeude.GB_SK_UID, '00000000-0000-0000-0000-000000000000') AS RPT_FID_SK_UID
,T_AP_Gebaeude.GB_SO_UID AS RPT_FID_SO_UID
,T_AP_Gebaeude.GB_UID AS RPT_UID
--,T_AP_Gebaeude.GB_MDT_ID AS RPT_MDT_ID
--,ISNULL(GB_Nr, '') + ' - ' + ISNULL(GB_Bezeichnung, '') AS RPT_Name
,T_AP_Gebaeude.GB_Bezeichnung AS RPT_Name
--,T_AP_Gebaeude.GB_Bezeichnung AS RPT_Sort
,ROW_NUMBER() OVER (ORDER BY T_AP_Gebaeude.GB_Bezeichnung ASC) AS RPT_Sort
FROM T_AP_Gebaeude
WHERE (1=1)
-- AND (T_AP_Standort.SO_MDT_ID = @in_mandant)
AND (T_AP_Gebaeude.GB_Status = 1)
AND (T_AP_Gebaeude.GB_DatumBis >= CONVERT(char(8), { fn NOW() }, 112))
AND (T_AP_Gebaeude.GB_DatumVon <= { fn NOW() })
--AND ( ISNULL(T_AP_Gebaeude.GB_SK_UID, '00000000-0000-0000-0000-000000000000') IN (@Standortkategorie) )
AND ',' + @Standortkategorie + ',' LIKE '%,' + ISNULL(CAST(T_AP_Gebaeude.GB_SK_UID AS varchar(36)), '00000000-0000-0000-0000-000000000000') + ',%'
-- AND ( ISNULL(T_AP_Gebaeude.GB_SO_UID, '00000000-0000-0000-0000-000000000000') IN (@Standort) )
AND ',' + @Standort + ',' LIKE '%,' + ISNULL(CAST(T_AP_Gebaeude.GB_SO_UID AS varchar(36)), '00000000-0000-0000-0000-000000000000') + ',%'
/*
AND
(
( @in_groups = '0000')
OR
(
SELECT
ISNULL(SUM(CAST(SOR_IsRead AS int)), 0) AS SOR_IsRead
FROM T_SYS_Standortrechte
WHERE (1=1)
AND T_SYS_Standortrechte.SOR_SO_UID = T_AP_Standort.SO_UID
--AND SOR_SO_UID = '274751EB-AED4-4E4C-B6D1-57C4FDBC8925'
AND @in_groups LIKE '%,' + CAST(T_SYS_Standortrechte.SOR_GRANTEE_ID AS varchar(36)) + ',%'
) > 0
)
AND
(
( @in_groups = '0000')
OR
(
SELECT
ISNULL(SUM(CAST(GBR_IsRead AS int)), 0) AS GBR_IsRead
FROM T_SYS_Gebaeuderechte
WHERE (1=1)
AND T_SYS_Gebaeuderechte.GBR_GB_UID = T_AP_Gebaeude.GB_UID
--AND GBR_GB_UID = '274751EB-AED4-4E4C-B6D1-57C4FDBC8925'
AND @in_groups LIKE '%,' + CAST(T_SYS_Gebaeuderechte.GBR_GRANTEE_ID AS varchar(36)) + ',%'
) > 0
)
*/
)
GO