1

I'm currently working on a report in SSRS (SQL Server Reporting Services) where my data source is Databricks, accessed via ODBC. The report requires implementing a multi-select parameter for filtering results based on office names.

I have a SQL query that works perfectly with a single-select parameter using a question mark ? as a placeholder for dynamic input. However, I'm struggling to modify the query to support multi-select parameters. The query is supposed to filter results based on multiple office names, but I'm unable to pass a list or array to the single placeholder used for the IN clause. Here is the part of the query causing issues:

SELECT DISTINCT
       dimpractice.PracticeId,
       dimpractice.PracticeName AS Practice
FROM curated.dimprojectmaster
    INNER JOIN curated.dimorganization
        ON dimprojectmaster.OrganizationID = dimorganization.OrganizationID
    INNER JOIN curated.dimpractice
        ON dimorganization.PracticeID = dimpractice.PracticeID
    INNER JOIN curated.dimprofitcenter
        ON dimorganization.ProfitCenterID = dimprofitcenter.ProfitCenterID
    INNER JOIN curated.dimoffice
        ON dimprofitcenter.OfficeID = dimoffice.OfficeID
      AND dimprojectmaster.ChargeType IN ('Regular', 'Promotional')
AND dimoffice.OfficeName IN (?) 
ORDER BY Practice

dimoffice.OfficeName IN (?) -- This is where the problem occurs with multi-select

1
  • Directly pass the parameter just like below example then it will work SELECT TOP (1000) [SERIAL_NUMBER] FROM [OperationalReports].[dbo].[GB193010-BB] WHERE [SERIAL_NUMBER] IN (@ReportParameter1) Commented Sep 4, 2024 at 11:13

1 Answer 1

0

Use a CTE. This is roughly what it should look like.

with cteParams as 
(select explode(split(?, ',')) as MyParamValue)
SELECT DISTINCT
       dimpractice.PracticeId,
       dimpractice.PracticeName AS Practice
FROM curated.dimprojectmaster
    INNER JOIN curated.dimorganization
        ON dimprojectmaster.OrganizationID = dimorganization.OrganizationID
    INNER JOIN curated.dimpractice
        ON dimorganization.PracticeID = dimpractice.PracticeID
    INNER JOIN curated.dimprofitcenter
        ON dimorganization.ProfitCenterID = dimprofitcenter.ProfitCenterID
    INNER JOIN curated.dimoffice
        ON dimprofitcenter.OfficeID = dimoffice.OfficeID
      AND dimprojectmaster.ChargeType IN ('Regular', 'Promotional')
    inner join cteParams on dimoffice.OfficeName = cteParams.MyParamValue
ORDER BY Practice
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.