t-sql 2008 parameter

  • In t-sql 2008 r2 I would like to know how to set a variable value that would be similar to

    declare @avar varchar(3)

    set @avar in ('ABS', YUR', 'UNV', 'MED')

    The @avar character can be one or all of the values listed above.

    I want to be able to set a variable like this since the user can select one, 2, 3, or 4 of the values listed above in an ssrs 2008 r2 report.

  • Can't you just set the parameter to be multi-valued in the report? Then you can use JOIN() to get the items in the list into a single string...

    Or did I misunderstand what you were asking?

  • Wendy,

    I think what you want to do is something like this.

    -- Create the type for your db

    CREATE TYPE dbo.avar AS TABLE

    (

    avar VARCHAR(3)

    );

    GO

    -- Locally, you can use DECLARE to create a table based on the TYPE

    DECLARE @avar dbo.avar;

    -- Populate the table

    INSERT INTO @avar

    SELECT 'ABS' UNION ALL SELECT 'YUR' UNION ALL SELECT 'UNV' UNION ALL SELECT 'MED';

    SELECT * FROM @avar;

    -- or

    SELECT *

    FROM YourTable

    WHERE avar IN (SELECT avar FROM @avar);

    GO

    DROP TYPE dbo.avar;


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • In SSRS, you can have a drop down, and set Datasource as a table(As wendy mentioned, create a table with all your values), you can set property of the drop down as multiselect.

  • Thanks a lot!

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply