Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. how to write a query with multiple random filters ?

how to write a query with multiple random filters ?

Scheduled Pinned Locked Moved Database
tutorialdatabasequestionlounge
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pdeveloper
    wrote on last edited by
    #1

    Hi, I have to write a query where there will be multiple filters selected by user. These filters will be selected randomly in any combination (for example filters like: Co.name, deptId, Startdate, endDate, employee name, Assignment, Shifts, class) Can anyone tell me how to write such type of query? As there cn be n numbers of permutation & combination of all filters.

    S 1 Reply Last reply
    0
    • P Pdeveloper

      Hi, I have to write a query where there will be multiple filters selected by user. These filters will be selected randomly in any combination (for example filters like: Co.name, deptId, Startdate, endDate, employee name, Assignment, Shifts, class) Can anyone tell me how to write such type of query? As there cn be n numbers of permutation & combination of all filters.

      S Offline
      S Offline
      Simon_Whale
      wrote on last edited by
      #2

      one solution that I have used before is

      select *
      from table
      where ((@endDate is null) or (enddate = @enddate)) and
      ((@deptid is null) or (deptid = @deptid)) and
      ((@employeeName is null) or (employeeName = @employeeName))

      Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

      P 2 Replies Last reply
      0
      • S Simon_Whale

        one solution that I have used before is

        select *
        from table
        where ((@endDate is null) or (enddate = @enddate)) and
        ((@deptid is null) or (deptid = @deptid)) and
        ((@employeeName is null) or (employeeName = @employeeName))

        Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

        P Offline
        P Offline
        Pdeveloper
        wrote on last edited by
        #3

        Thanks Simon..for ur reply will implement this today and let u know..hope this works for me.

        1 Reply Last reply
        0
        • S Simon_Whale

          one solution that I have used before is

          select *
          from table
          where ((@endDate is null) or (enddate = @enddate)) and
          ((@deptid is null) or (deptid = @deptid)) and
          ((@employeeName is null) or (employeeName = @employeeName))

          Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

          P Offline
          P Offline
          Pdeveloper
          wrote on last edited by
          #4

          This is not working in case I dont give deptid or any one of parameters. pls help me.

          M T 2 Replies Last reply
          0
          • P Pdeveloper

            This is not working in case I dont give deptid or any one of parameters. pls help me.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            What simon supplied is the idea/concept of how it should be done, writing the actual query is up to you. The sample shows you that simon is testing the value of the variable to find out if it is null and if it is not null then applying the filter. You need to understand the concept and extend it to your needs. That is called learning!

            Never underestimate the power of human stupidity RAH

            1 Reply Last reply
            0
            • P Pdeveloper

              This is not working in case I dont give deptid or any one of parameters. pls help me.

              T Offline
              T Offline
              thatraja
              wrote on last edited by
              #6

              Share your query first

              thatraja

              Code converters | Education Needed No thanks, I am all stocked up. - Luc Pattyn When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups