问题
I have 1 table. 1 have 1 multi-value parameter listing all properties called PROPERTIES. I want the table to display 1 property per row at a time.
The table has roughly 20 columns, referencing different datasets throughout.
All of the datasets that reference the property have a: WHERE RMPROPID IN (@PROPERTIES)
and the dataset has @PROPERTIES
value of: =JOIN(Parameters!PROPERTIES.Value,",")
(This creates the list of properties selected)
The table has a single row, referencing the different datasets. The tables dataset is SelectedProperties
and the group by on the row is =Fields!RMPROPID.Value
The SelectedProperties
dataset looks like this:
SELECT
RMPROPID,
propname
FROM
RMPROP
WHERE
RMPROPID IN (@PROPERTIES)
Whenever I choose more than one property it does not work. Nothing is returned. Is there a trick I am missing? I want 1 row to reference one property at a time.
回答1:
The problem is your redefintion of the parameter as you pass it to the query:
You shouldn't have this part:
=JOIN(Parameters!PROPERTIES.Value,",")
This doesn't create a list of the selected values. It creates a single value that is a string combining all of the selected values.
Replace the bit above with just =Parameters!PROPERTIES.Value
. SSRS will take care or putting the multiple values into the SQL query appropriately.
回答2:
You should be able to put the index at the end like so:
Parameters!< ParameterName>.Value(0)
You could do an index based on your row return or something similar to that.
More info here: http://msdn.microsoft.com/en-us/library/aa337292(v=sql.90).aspx
回答3:
A non-performant but working way is to use varchar(MAX) and get the UIDs in comma-separated fashion.
Then you can do a LIKE on it:
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
来源:https://stackoverflow.com/questions/15235518/how-to-use-multivalue-parameters-in-ssrs