I've got a report that has 6 parameters. All parameters need to be optional and 3 have to be multi-value. One of the optional parameters is a dropdown, the rest are manually keyed in text boxes. The Where clause below works when there are multiple @VendorNum values and one @FullJA value, but fails with multiple @FullJA values regardless of the @VendorNum count.
Parameters: @VendorNum - keyed manually by user (space delimited) - optional, can be multivalue @FullJA - keyed manually by user (space delimited) - optional, can be multivalue @BU - optional, can be multivalue - when @JA is populated, this will auto-populate, if @JA isn't populated it's a dropdown with all selected. @JA3 - keyed by user - optional, single value @StartDate and @EndDate - optional single values
select * from some_table
WHERE
/*FULL JA*/
(
SUBSTRING(VendorNum, PATINDEX('%[^0]%', VendorNum + '.'), LEN(VendorNum)
) IN (@VendorNum)
AND LEFT(JA, 7) IN (@FullJA)
AND BU IN(@BU)
AND @JA3 IS NULL
)
OR
/*DATE RANGE*/
(
SUBSTRING(VendorNum, PATINDEX('%[^0]%', VendorNum + '.'), LEN(VendorNum)
) IN (@VendorNum)
AND LEN(ISNULL(CONVERT(VARCHAR(20), Cleared_When), '0')) >= @ClearedOnly
AND ad.Audit_Publish_Date >= ISNULL(@StartDate, '2015-01-01')
AND ad.Audit_Publish_Date <= ISNULL(@EndDate, '2025-12-31')
AND BU IN (@BU)
AND @FullJA IS NULL
AND @JA3 IS NULL
)
/*BUS UNIT AND JA3*/
OR (
SUBSTRING(VendorNum, PATINDEX('%[^0]%', VendorNum + '.'), LEN(VendorNum)
) IN (@VendorNum)
AND BU IN (@BU)
AND ad.Audit_Publish_Date >= ISNULL(@StartDate, '2015-01-01')
AND ad.Audit_Publish_Date <= ISNULL(@EndDate, '2025-12-31')
AND LEFT(JA, 3) = (@JA3)
AND @FullJA IS NULL
)
/*BUS UNIT ONLY*/
OR (
SUBSTRING(VendorNum, PATINDEX('%[^0]%', VendorNum + '.'), LEN(VendorNum)
) IN (@VendorNum)
AND BU IN (@BU)
AND ad.Audit_Publish_Date >= ISNULL(@StartDate, '2015-01-01')
AND ad.Audit_Publish_Date <= ISNULL(@EndDate, '2025-12-31')
AND @JA3 IS NULL
AND @FullJA IS NULL
)
The dataset parameter values for @FullJA and @VendorNum are both =IIF(InStr(Parameters!FullJA.Value," ")>0,SPLIT(Parameters!FullJA.Value," "),Parameters!FullJA.Value) and all params are set as NOT multivalue, with nulls allowed.
Any help would be greatly appreciated. I've written over 200 reports for this project and this is the only one that is really grinding my gears!
Thanks!