SSRS Report Works when the Parameter uses the "=" Operator but not "IN"

kredeker54

I will try to keep this short.

I have a report in SSRS where the @Position parameter needs to be able to accept multiple values (see the parameter in the WHERE clause below).

DECLARE @multiplier INT;

SET @multiplier = 30

SELECT p.Fname, 
       p.Lname,
       p.Position,
       (SUM(plg.PTS)/SUM(plg.MP))*@multiplier AS PTS,
       (SUM(plg.TRB)/SUM(plg.MP))*@multiplier AS TRB,
       (SUM(plg.AST)/SUM(plg.MP))*@multiplier AS AST,
       (SUM(plg.BLK)/SUM(plg.MP))*@multiplier AS BLK,
       (SUM(plg.STL)/SUM(plg.MP))*@multiplier AS STL,      
       (SUM(plg.TOV)/SUM(plg.MP))*@multiplier AS TOV,
       (SUM(plg.FT)/SUM(plg.MP))*@multiplier AS FTs,
       --SUM(plg.FTA)/SUM(plg.MP))*@multiplier AS FTAs,
       SUM(plg.FT)/SUM(plg.FTA) AS FT_Percentage,
       (SUM(plg.FG)/SUM(plg.MP))*@multiplier AS FGs,
       --SUM(plg.FGA)/SUM(plg.MP))*@multiplier AS FGAs,
       SUM(FG)/SUM(FGA) as Field_Percentage,
       (SUM(plg.[3P])/SUM(plg.MP))*@multiplier AS Threes,
       --SUM(plg.[3PA])/SUM(plg.MP))*@multiplier AS TP%
       SUM([3P])/SUM([3PA]) AS Three_Point_Percentage
FROM PlayerGameLog plg
INNER JOIN Players p
ON p.PlayerID = plg.PlayerID
WHERE plg.PlayerID IN (SELECT PlayerID
            FROM Players
            WHERE lname != 'westbrook')
    AND p.TeamID = 'OKC'
    AND p.Position = @Position
GROUP BY p.Fname, p.Lname, p.Position
ORDER BY PTS DESC;

If I change the following line:

AND p.Position = @Position

To:

AND p.Position IN @Position

I get a message that prompts me to Define Query Paramters. No matter what I set those to, I encounter a message that says there is an error. I've changed the parameter to allow multiple values, and still no dice. Any ideas?

ErikE

You're getting confused between the scope of the different parts of an SQL query.

Consider these two clauses:

WHERE Position IN ('1', '2', '3')
WHERE Position IN ('1, 2, 3')

Can you see that these are not equivalent? The first one is looking for any one of three single-digit values. The second one is looking for a SINGLE value, a string 7 characters long having 3 digits, 2 spaces, and 2 commas.

When you do Position IN @Position, you're performing something like the second expression. The problem, of course, is that the string contents don't somehow "break out" of their value and become SQL so that they represent three values. It's one value, and one value it will stay.

I encourage you first to stop using a stored procedure and write your code in an application layer where you can compose the SQL statement you want. You can then build a proper SQL statement using IN. Or you could insert to a temp table and join to that.

Alternately, if you absolutely must continue using a stored procedure, then parse the contents of @Position into a temp table or table variable. Look up SQL string splitting.

Finally, as mentioned in another answer, you could use dynamic SQL, but this is best avoided. Don't go there if you can help it. I promise you, it's not good to go down this route if you can at ALL avoid it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Report Parameter validation in ssrs report

From Dev

SSRS report - Casing parameter

From Dev

Add a filter parameter to ssrs report

From Dev

SSRS - Report Based on Parameter Selection

From Dev

SSRS 2008 - Dynamic parameter works in Visual Studio, but has no available values on the Report Server

From Dev

AX SSRS Report Parameter is shown but not useable in the report

From Dev

SSRS Report Parameter Default Null Value not Applied

From Dev

SSRS - Custom parameter layout was removed from the report

From Dev

Pass query string parameter to SSRS report

From Dev

Using SSRS join on the parameter passed in the report

From Dev

Correctly wrap double quote to SSRS report parameter

From Dev

SSRS passing multiple string parameter to another report

From Dev

How to send parameter of a report to another? SSRS

From Dev

SSRS - Getting report selected parameter with JavaScript

From Dev

Pass query string parameter to SSRS report

From Dev

SSRS Passing multi-select parameter to report

From Dev

Scope parameter issue in SSRS report Expression

From Dev

Month and Year options parameter in SSRS report

From Dev

For an SSRS report with multi select parameters, when I 'select all' for a parameter having a long list of values, report throws a javascript error

From Dev

Set SSRS Report Parameter value with passed Querystring value in SSRS

From Dev

Change value of SSRS report parameter based on the input of another parameter

From Dev

SSRS 2008: Show report parameter in textbox if parameter is not NULL or blank

From Dev

Adding values to a Report when there is no Data in query SSRS

From Dev

Tablix border inconsistent when zooming into ssrs report

From Dev

trigger SSRS report when finishing a SSIS job

From Dev

SSRS When uploading report owner name is wrong

From Dev

Freezing headers in SSRS report while scrolling works only in IE

From Dev

Freezing headers in SSRS report while scrolling works only in IE

From Dev

SSRS Single report parameter used to set dataset query parameters

Related Related

  1. 1

    Report Parameter validation in ssrs report

  2. 2

    SSRS report - Casing parameter

  3. 3

    Add a filter parameter to ssrs report

  4. 4

    SSRS - Report Based on Parameter Selection

  5. 5

    SSRS 2008 - Dynamic parameter works in Visual Studio, but has no available values on the Report Server

  6. 6

    AX SSRS Report Parameter is shown but not useable in the report

  7. 7

    SSRS Report Parameter Default Null Value not Applied

  8. 8

    SSRS - Custom parameter layout was removed from the report

  9. 9

    Pass query string parameter to SSRS report

  10. 10

    Using SSRS join on the parameter passed in the report

  11. 11

    Correctly wrap double quote to SSRS report parameter

  12. 12

    SSRS passing multiple string parameter to another report

  13. 13

    How to send parameter of a report to another? SSRS

  14. 14

    SSRS - Getting report selected parameter with JavaScript

  15. 15

    Pass query string parameter to SSRS report

  16. 16

    SSRS Passing multi-select parameter to report

  17. 17

    Scope parameter issue in SSRS report Expression

  18. 18

    Month and Year options parameter in SSRS report

  19. 19

    For an SSRS report with multi select parameters, when I 'select all' for a parameter having a long list of values, report throws a javascript error

  20. 20

    Set SSRS Report Parameter value with passed Querystring value in SSRS

  21. 21

    Change value of SSRS report parameter based on the input of another parameter

  22. 22

    SSRS 2008: Show report parameter in textbox if parameter is not NULL or blank

  23. 23

    Adding values to a Report when there is no Data in query SSRS

  24. 24

    Tablix border inconsistent when zooming into ssrs report

  25. 25

    trigger SSRS report when finishing a SSIS job

  26. 26

    SSRS When uploading report owner name is wrong

  27. 27

    Freezing headers in SSRS report while scrolling works only in IE

  28. 28

    Freezing headers in SSRS report while scrolling works only in IE

  29. 29

    SSRS Single report parameter used to set dataset query parameters

HotTag

Archive