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. "Stock Recon" type query .. most efficient route?

"Stock Recon" type query .. most efficient route?

Scheduled Pinned Locked Moved Database
databasequestion
6 Posts 3 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.
  • F Offline
    F Offline
    francoisdotnet
    wrote on last edited by
    #1

    Hi All I thought I'd put this to you, my fellow devs, as I just cant decide the most efficient route! :confused: Suppose I have 2 tables, 1: id, productid, datedelivered, qty AND 2: id, productid, datesold, qty I would like to end up having a result with: productid, monthvalue, openingbal, delivered, sold, closingbal (monthvalue being something like 2008-01-01, i.e. each like is the stock recon for the month) Now I know there are a few ways of doing this, one I thought of is with a cursor. But not being too clued up with the new features that 2005 provides I am not sure what the most efficient way would be ... any ideas? :doh: Thanks.

    P P 2 Replies Last reply
    0
    • F francoisdotnet

      Hi All I thought I'd put this to you, my fellow devs, as I just cant decide the most efficient route! :confused: Suppose I have 2 tables, 1: id, productid, datedelivered, qty AND 2: id, productid, datesold, qty I would like to end up having a result with: productid, monthvalue, openingbal, delivered, sold, closingbal (monthvalue being something like 2008-01-01, i.e. each like is the stock recon for the month) Now I know there are a few ways of doing this, one I thought of is with a cursor. But not being too clued up with the new features that 2005 provides I am not sure what the most efficient way would be ... any ideas? :doh: Thanks.

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      Francois Searle wrote:

      one I thought of is with a cursor

      Stored procedures would probably be better performance-wise.

      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

      F 1 Reply Last reply
      0
      • F francoisdotnet

        Hi All I thought I'd put this to you, my fellow devs, as I just cant decide the most efficient route! :confused: Suppose I have 2 tables, 1: id, productid, datedelivered, qty AND 2: id, productid, datesold, qty I would like to end up having a result with: productid, monthvalue, openingbal, delivered, sold, closingbal (monthvalue being something like 2008-01-01, i.e. each like is the stock recon for the month) Now I know there are a few ways of doing this, one I thought of is with a cursor. But not being too clued up with the new features that 2005 provides I am not sure what the most efficient way would be ... any ideas? :doh: Thanks.

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        A cursor is probably one of the worst ways you could do this. You should always attempt, where possible, to use set based queries as they are what database engines are designed to do.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        F 1 Reply Last reply
        0
        • P Paul Conrad

          Francois Searle wrote:

          one I thought of is with a cursor

          Stored procedures would probably be better performance-wise.

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

          F Offline
          F Offline
          francoisdotnet
          wrote on last edited by
          #4

          Yes, I agree it should be within a SP, but I was referring more to the SQL within the SP, the methodology as such.

          P 1 Reply Last reply
          0
          • P Pete OHanlon

            A cursor is probably one of the worst ways you could do this. You should always attempt, where possible, to use set based queries as they are what database engines are designed to do.

            Deja View - the feeling that you've seen this post before.

            My blog | My articles

            F Offline
            F Offline
            francoisdotnet
            wrote on last edited by
            #5

            I know cursors are the worst way, but currently my attempt at doing it using "normal" sql queries is running too long. Surely this must be a common query? I mean there are so many scenarios where this type of "dataset" is needed.

            1 Reply Last reply
            0
            • F francoisdotnet

              Yes, I agree it should be within a SP, but I was referring more to the SQL within the SP, the methodology as such.

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #6

              If you are going the standard sql route and it is slow, maybe query analyzer could shed some light for you where bottlenecks are.

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

              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