Good day,
I'm trying to pass multiple SSRS/SSDT parameter values, to a parameter used in my OPENQUERY statement.
What I've done thus far:
i. The specific "Sample Point" parameter's properties, has been checked, to "Allow multiple values", in SSRS/SSDT.
a. Multiple "Sample Point" values can be selected successfully: https://i.stack.imgur.com/lAigV.png b. List of "Sample Point" values, as it appears after selection: https://i.stack.imgur.com/fvgyy.png
ii. The "Sample Point" parameter's, "Parameter Value" expression, in the Dataset, has been set to:
=Split(Join(Parameters!SamplePoint.Value,", "),", ")
iii. The code below, utlises an OPENQUERY statement, to extract a "Property List", based on the "Sample Point(s)", selected:
BEGIN
DECLARE @cSQL nvarchar(max)
DECLARE @cEquipment nvarchar(50) = LTRIM('SOLVENTS WEST')
DECLARE @pStartDate datetime = '2022-11-01 00:00:00'
DECLARE @pEndDate datetime = '2022-11-05 00:00:00'
DECLARE @cSamplePoint nvarchar(max)
DECLARE @cStartDate nvarchar(30) = SUBSTRING(CONVERT(varchar(20), @pStartDate, 120), 1, 10)
DECLARE @cEndDate nvarchar(30) = SUBSTRING(CONVERT(varchar(20), @pEndDate, 120), 1, 10)
SET @cSamplePoint = REPLACE(REPLACE(@SamplePoint, ', ', ','), ',', ''',''')
SELECT @cSQL = 'SELECT
''N.A.'' AS PropertyName
UNION
SELECT DISTINCT
PropertyName
FROM
OPENQUERY(**[LINKSERVPRD.ORACLE**],
''SELECT
r.prprty_name AS PropertyName
FROM
totalplant.ip_a e,
totalplant.ip_b s,
totalplant.ip_b t,
totalplant.ip_c r
WHERE
e.eq_name = ''''' + @cEquipment + '''''
AND s.smpl_pnt_name IN ( ''''' + @cSamplePoint + ''''')
AND s.smpl_dt_tm BETWEEN TO_DATE(''''' + @cStartDate + ''''', ''''YYYY-MM-DD HH24:MI:SS'''') AND TO_DATE(''''' + @cEndDate + ''''', ''''YYYY-MM-DD HH24:MI:SS'''')'')
ORDER BY
PropertyName'
EXEC (@cSQL)
END
iv. Selecting a single "Sample Point", populates the "Property List" successfully: https://i.stack.imgur.com/v8sOU.png
v. Selecting multiple "Sample Points", generates an error message. I fail to understand, since my REPLACE statement is, as far as I know, correct: https://i.stack.imgur.com/6ArZ2.png
vi. Any assistance will be greatly appreciated.