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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. IN Clause Best Practices? [solved]

IN Clause Best Practices? [solved]

Scheduled Pinned Locked Moved Database
questiondatabasehelpcsharpdata-structures
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.
  • D Offline
    D Offline
    Dan Mos
    wrote on last edited by
    #1

    Hy, I have a problem in that I don't know what to choose. We have somewhere DataLayer/BussinessLogic something like:

    public class MainClass{
    .
    .
    .
    protected ObservableCollection<SecondaryClass> lst;//contected to the main class through IDs in the DB
    .
    .
    .
    }

    So the question is: What is the best way to get some rows based on a array/list of IDs from the "main" table: 1) Getting all the MainClass rows/objects than generating a string from code(c#) using StringBuilder with all the IDs separated by commas and run a query/storedproc to get all objects from the realted table(s) with a string/varchar paramter for the IN clause and fill the list of SecondaryClass objects from the MainClass or 2) Generate a temporary table with the IDs and use that in another query/proc as the IN or EXISTS filter? I've run some tests and for some reason or another from the speed point of view the first one is the winner. But both are pretty fast. So speed alone is not that big of an issue. Because of the Object Model we can not use a join. I mean we could but makes no sence. Any suggestions will be apreciated. Thanks

    I bug

    modified on Wednesday, July 14, 2010 1:47 PM

    L 1 Reply Last reply
    0
    • D Dan Mos

      Hy, I have a problem in that I don't know what to choose. We have somewhere DataLayer/BussinessLogic something like:

      public class MainClass{
      .
      .
      .
      protected ObservableCollection<SecondaryClass> lst;//contected to the main class through IDs in the DB
      .
      .
      .
      }

      So the question is: What is the best way to get some rows based on a array/list of IDs from the "main" table: 1) Getting all the MainClass rows/objects than generating a string from code(c#) using StringBuilder with all the IDs separated by commas and run a query/storedproc to get all objects from the realted table(s) with a string/varchar paramter for the IN clause and fill the list of SecondaryClass objects from the MainClass or 2) Generate a temporary table with the IDs and use that in another query/proc as the IN or EXISTS filter? I've run some tests and for some reason or another from the speed point of view the first one is the winner. But both are pretty fast. So speed alone is not that big of an issue. Because of the Object Model we can not use a join. I mean we could but makes no sence. Any suggestions will be apreciated. Thanks

      I bug

      modified on Wednesday, July 14, 2010 1:47 PM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hi, Have you considered Table Valued Parameters[^]?

      I are Troll :suss:

      D 1 Reply Last reply
      0
      • L Lost User

        Hi, Have you considered Table Valued Parameters[^]?

        I are Troll :suss:

        D Offline
        D Offline
        Dan Mos
        wrote on last edited by
        #3

        :thumbsup: Nope. Nice solution. Thanks

        I bug

        L 1 Reply Last reply
        0
        • D Dan Mos

          :thumbsup: Nope. Nice solution. Thanks

          I bug

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You're welcome :)

          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