Passing filtering rules into a query

Posted on 2012-08-21
Last Modified: 2012-08-21
I am writing a report/query that pulls back a certain amount of records and then further filters them using rules that they can build. I was going to store the rules in an sql table and then use them when they call the query.  How can I pass those rules into the query?  an example of a rule is flag false when product was used in the last 120 days.  Thanks in advance.
Question by:mwhodges
    LVL 83

    Expert Comment

    You have to do some appending and string manipulation.

    Author Comment

    Can I load the rules into an array and then how can I pass them?
    LVL 83

    Accepted Solution

    Loop through the array like

    Dim str As string = "Select * From ... Where "
    For each rule As String in Rules
       str &= Rule & " AND"
    str = str.Trim.Trim("AND").Trim

    Author Closing Comment

    Thanks exactly what I needed.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now