Multiple Filters & Mulitple Options

Last post 10-30-2006 8:02 PM by agolden. 1 replies.

Sort Posts:

  • Multiple Filters & Mulitple Options

    10-30-2006, 3:45 PM
    • Loading...
    • cush
    • Joined on 12-27-2004, 9:29 PM
    • Central Valley, CA
    • Posts 1

    First post, go easy on me.

    I have a table with 3 fields I need to filter with, ClientName(text), Status(text), LocationID(int32).

    I can create a where statement that filters all three, when there is a selection for each one.

    However, what I need is for the user to be able to pick and choose.  Not having to provide a selection for each one.  So they have multiple filter options.  Using combinations of the three filters. 

    I am not able to create a statement that properly filters when one of the filters is not used.

    Thanks for any help.  I have been banging my head for along time.

  • Re: Multiple Filters & Mulitple Options

    10-30-2006, 8:02 PM
    Answer
    • Loading...
    • agolden
    • Joined on 08-03-2002, 6:56 AM
    • Houston. TX
    • Posts 587

    Try something like this:

    SELECT c.ClientName, c.Status, c.LocationID FROM dbo.Clients c
    WHERE ((@ClientName IS NULL) OR (c.ClientName = @ClientName))
    	AND ((@Status IS NULL) OR (c.Status = @Status))
    	AND ((@LocationID IS NULL) OR (c.LocationID = @LocationID))

    and either pass it a value to filer on or a dbnull for each of the three parameters.

    Hope that helps.

    Aaron

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter