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. Nested Select statement

Nested Select statement

Scheduled Pinned Locked Moved Database
helpcssdatabase
4 Posts 2 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
    Prakash_Mishra
    wrote on last edited by
    #1

    Hi all I have an issue with select statement. Like in one form i have 5 fields all combo box and after selecting all we have search option so in a data grid i am displaying the records which satisfies all criteria in the combo box. It works fine. But now i want is if user select only one combo box and press search the grid should show the related records which satisfies the combo box condition. I have tried with AND OR condition in query but not getting the proper records. Pl help Regards

    Prakash Mishra(Banglore,India)

    K P 2 Replies Last reply
    0
    • P Prakash_Mishra

      Hi all I have an issue with select statement. Like in one form i have 5 fields all combo box and after selecting all we have search option so in a data grid i am displaying the records which satisfies all criteria in the combo box. It works fine. But now i want is if user select only one combo box and press search the grid should show the related records which satisfies the combo box condition. I have tried with AND OR condition in query but not getting the proper records. Pl help Regards

      Prakash Mishra(Banglore,India)

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      There are several ways to solve this problem, I will suggest one of them here. If you have five parameters you need to set up your where clause to allow each of the parameters to be optional. All of this is done in the where clause. So the code would look like this if a parameter is being passed in then you need to set it to a default value. I will assume that all your parameters are strings. Where (param1 = '' or param1 = @param1) and (param2 = '' or param2 = @param2) and (param3 = '' or param3 = @param3) and (param4 = '' or param4 = @param4) and (param5 = '' or param5 = @param5) So the idea is if the user only selects one combo box, just set the rest of the parameters to '' and your query should work. Hope that helps. Ben

      P 1 Reply Last reply
      0
      • P Prakash_Mishra

        Hi all I have an issue with select statement. Like in one form i have 5 fields all combo box and after selecting all we have search option so in a data grid i am displaying the records which satisfies all criteria in the combo box. It works fine. But now i want is if user select only one combo box and press search the grid should show the related records which satisfies the combo box condition. I have tried with AND OR condition in query but not getting the proper records. Pl help Regards

        Prakash Mishra(Banglore,India)

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

        I was waiting for reply from 5 long hours but didn't got a single one at last i solved the problem of my own. for for others reference i am posting the solution select * from table name (must condition and 1st condition)or (must condition and 2nd condition)or (must condition and 3rd condition)....

        Prakash Mishra(Banglore,India)

        1 Reply Last reply
        0
        • K kubben

          There are several ways to solve this problem, I will suggest one of them here. If you have five parameters you need to set up your where clause to allow each of the parameters to be optional. All of this is done in the where clause. So the code would look like this if a parameter is being passed in then you need to set it to a default value. I will assume that all your parameters are strings. Where (param1 = '' or param1 = @param1) and (param2 = '' or param2 = @param2) and (param3 = '' or param3 = @param3) and (param4 = '' or param4 = @param4) and (param5 = '' or param5 = @param5) So the idea is if the user only selects one combo box, just set the rest of the parameters to '' and your query should work. Hope that helps. Ben

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

          Thanks Ben i solved the problem of my own at last from morning i was trying and didn't got any reply. I am new to sql, Regards

          Prakash Mishra(Banglore,India)

          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