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. Other Discussions
  3. The Weird and The Wonderful
  4. Found this a few minutes ago

Found this a few minutes ago

Scheduled Pinned Locked Moved The Weird and The Wonderful
sharepoint
9 Posts 6 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.
  • S Offline
    S Offline
    SomeGuyThatIsMe
    wrote on last edited by
    #1

    Found this in a sp, not sure why it was done this way, @fileLength and @userId are passed in, and i've changed the names of the tables so i could post this, so i realize the tables may not make sense(they do in the real code).

    DECLARE file_Cursor CURSOR FOR SELECT Length
    FROM Files f
    INNER JOIN User p
    ON p.UserId = f.UserId
    INNER JOIN Playlist pm
    ON pm.ListId = p.DefaultListId
    WHERE p.UserId = @userId
    AND pm.FileNumber <> -1

    -- get total length
    OPEN file_Cursor
    FETCH NEXT FROM file_Cursor INTO @length

    WHILE @@FETCH_STATUS = 0
    BEGIN
    SET @fileLength = @fileLength + @length

        FETCH NEXT FROM file\_Cursor INTO @length
    

    END

    CLOSE file_Cursor
    DEALLOCATE file_Cursor

    Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

    J A L J S 5 Replies Last reply
    0
    • S SomeGuyThatIsMe

      Found this in a sp, not sure why it was done this way, @fileLength and @userId are passed in, and i've changed the names of the tables so i could post this, so i realize the tables may not make sense(they do in the real code).

      DECLARE file_Cursor CURSOR FOR SELECT Length
      FROM Files f
      INNER JOIN User p
      ON p.UserId = f.UserId
      INNER JOIN Playlist pm
      ON pm.ListId = p.DefaultListId
      WHERE p.UserId = @userId
      AND pm.FileNumber <> -1

      -- get total length
      OPEN file_Cursor
      FETCH NEXT FROM file_Cursor INTO @length

      WHILE @@FETCH_STATUS = 0
      BEGIN
      SET @fileLength = @fileLength + @length

          FETCH NEXT FROM file\_Cursor INTO @length
      

      END

      CLOSE file_Cursor
      DEALLOCATE file_Cursor

      Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

      J Offline
      J Offline
      Jan Steyn
      wrote on last edited by
      #2

      DBA should be shot for having allowed this to persist in his/her server!

      S 1 Reply Last reply
      0
      • J Jan Steyn

        DBA should be shot for having allowed this to persist in his/her server!

        S Offline
        S Offline
        SomeGuyThatIsMe
        wrote on last edited by
        #3

        we dont have an offical dba, we were trusted to check our own stuff once we proved we were doing things right (small shop). obviously nobody ever checked the proc this was in regardless of my recomending they do so.

        Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

        1 Reply Last reply
        0
        • S SomeGuyThatIsMe

          Found this in a sp, not sure why it was done this way, @fileLength and @userId are passed in, and i've changed the names of the tables so i could post this, so i realize the tables may not make sense(they do in the real code).

          DECLARE file_Cursor CURSOR FOR SELECT Length
          FROM Files f
          INNER JOIN User p
          ON p.UserId = f.UserId
          INNER JOIN Playlist pm
          ON pm.ListId = p.DefaultListId
          WHERE p.UserId = @userId
          AND pm.FileNumber <> -1

          -- get total length
          OPEN file_Cursor
          FETCH NEXT FROM file_Cursor INTO @length

          WHILE @@FETCH_STATUS = 0
          BEGIN
          SET @fileLength = @fileLength + @length

              FETCH NEXT FROM file\_Cursor INTO @length
          

          END

          CLOSE file_Cursor
          DEALLOCATE file_Cursor

          Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

          A Offline
          A Offline
          agolddog
          wrote on last edited by
          #4

          Well, that's probably what sum(length) would do anyway... Sigh. Good find, good fix.

          1 Reply Last reply
          0
          • S SomeGuyThatIsMe

            Found this in a sp, not sure why it was done this way, @fileLength and @userId are passed in, and i've changed the names of the tables so i could post this, so i realize the tables may not make sense(they do in the real code).

            DECLARE file_Cursor CURSOR FOR SELECT Length
            FROM Files f
            INNER JOIN User p
            ON p.UserId = f.UserId
            INNER JOIN Playlist pm
            ON pm.ListId = p.DefaultListId
            WHERE p.UserId = @userId
            AND pm.FileNumber <> -1

            -- get total length
            OPEN file_Cursor
            FETCH NEXT FROM file_Cursor INTO @length

            WHILE @@FETCH_STATUS = 0
            BEGIN
            SET @fileLength = @fileLength + @length

                FETCH NEXT FROM file\_Cursor INTO @length
            

            END

            CLOSE file_Cursor
            DEALLOCATE file_Cursor

            Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

            L Offline
            L Offline
            Leng Vang
            wrote on last edited by
            #5

            Because he/she was bored or they get paid by the number lines of code produced. :)

            1 Reply Last reply
            0
            • S SomeGuyThatIsMe

              Found this in a sp, not sure why it was done this way, @fileLength and @userId are passed in, and i've changed the names of the tables so i could post this, so i realize the tables may not make sense(they do in the real code).

              DECLARE file_Cursor CURSOR FOR SELECT Length
              FROM Files f
              INNER JOIN User p
              ON p.UserId = f.UserId
              INNER JOIN Playlist pm
              ON pm.ListId = p.DefaultListId
              WHERE p.UserId = @userId
              AND pm.FileNumber <> -1

              -- get total length
              OPEN file_Cursor
              FETCH NEXT FROM file_Cursor INTO @length

              WHILE @@FETCH_STATUS = 0
              BEGIN
              SET @fileLength = @fileLength + @length

                  FETCH NEXT FROM file\_Cursor INTO @length
              

              END

              CLOSE file_Cursor
              DEALLOCATE file_Cursor

              Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #6

              SomeGuyThatIsMe wrote:

              Found this in a sp, not sure why it was done this way

              People new to SQL who are use to standard declarative languages don't realize how sets work. They find it difficult to think that way even presuming they know that it exists. So they create loops.

              S 1 Reply Last reply
              0
              • J jschell

                SomeGuyThatIsMe wrote:

                Found this in a sp, not sure why it was done this way

                People new to SQL who are use to standard declarative languages don't realize how sets work. They find it difficult to think that way even presuming they know that it exists. So they create loops.

                S Offline
                S Offline
                SomeGuyThatIsMe
                wrote on last edited by
                #7

                I wouldnt have posted, well ok maybe i would have, if this was a new or junior person. If they were still around i would have tried to help them. This was written near the end of their time with the company, maybe that explains it. This person also spent a lot of time trying to prove how much smarter they were than everyone else.

                Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

                J 1 Reply Last reply
                0
                • S SomeGuyThatIsMe

                  I wouldnt have posted, well ok maybe i would have, if this was a new or junior person. If they were still around i would have tried to help them. This was written near the end of their time with the company, maybe that explains it. This person also spent a lot of time trying to prove how much smarter they were than everyone else.

                  Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #8

                  SomeGuyThatIsMe wrote:

                  I wouldnt have posted, well ok maybe i would have, if this was a new or junior person

                  I said "new to SQL" and not new to programming. And that is what I meant. Someone new to programming might be more likely to do it correctly because they don't already have expectations of how it 'should' be done. But these days either is likely to due a google search an implement it using the first example they find because neither has the necessary knowledge to filter it out.

                  1 Reply Last reply
                  0
                  • S SomeGuyThatIsMe

                    Found this in a sp, not sure why it was done this way, @fileLength and @userId are passed in, and i've changed the names of the tables so i could post this, so i realize the tables may not make sense(they do in the real code).

                    DECLARE file_Cursor CURSOR FOR SELECT Length
                    FROM Files f
                    INNER JOIN User p
                    ON p.UserId = f.UserId
                    INNER JOIN Playlist pm
                    ON pm.ListId = p.DefaultListId
                    WHERE p.UserId = @userId
                    AND pm.FileNumber <> -1

                    -- get total length
                    OPEN file_Cursor
                    FETCH NEXT FROM file_Cursor INTO @length

                    WHILE @@FETCH_STATUS = 0
                    BEGIN
                    SET @fileLength = @fileLength + @length

                        FETCH NEXT FROM file\_Cursor INTO @length
                    

                    END

                    CLOSE file_Cursor
                    DEALLOCATE file_Cursor

                    Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

                    S Offline
                    S Offline
                    StatementTerminator
                    wrote on last edited by
                    #9

                    Wow, talk about doing it the hard (and wrong) way. I suspect that this is a symptom of the state of on-the-job training in the programming world. It usually goes like "hey here's a new programmer, do this." But I still don't see how one becomes a programmer without learning the basics of SQL. No one likes code reviews, but it's useful for things like this. Also, I love how @@FETCH_STATUS is global. I once saw an expensive production system blow-up due to a legacy code time bomb in the form of a SP using a global variable like this.

                    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