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. bad SQL case

bad SQL case

Scheduled Pinned Locked Moved The Weird and The Wonderful
database
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.
  • C Offline
    C Offline
    crazedDotNetDev
    wrote on last edited by
    #1

    I want to throw my computer off the roof. I'm modifying a 700+ line stored procedure and this is done a dozen+ times.

    ( CASE WHEN [SomeID] IN ( [batch of hardcoded, unique ids] )
    THEN [hardcoded enum]
    ELSE ( CASE WHEN [SomeID] IN ( [batch of hardcoded, unique ids] )
    THEN [hardcoded enum]
    ELSE ( CASE WHEN [SomeID] IN ( [batch of hardcoded, unique ids] )
    THEN [hardcoded enum]
    ELSE …etc…
    END )
    END )
    END )

    I …just… :((

    B K 2 Replies Last reply
    0
    • C crazedDotNetDev

      I want to throw my computer off the roof. I'm modifying a 700+ line stored procedure and this is done a dozen+ times.

      ( CASE WHEN [SomeID] IN ( [batch of hardcoded, unique ids] )
      THEN [hardcoded enum]
      ELSE ( CASE WHEN [SomeID] IN ( [batch of hardcoded, unique ids] )
      THEN [hardcoded enum]
      ELSE ( CASE WHEN [SomeID] IN ( [batch of hardcoded, unique ids] )
      THEN [hardcoded enum]
      ELSE …etc…
      END )
      END )
      END )

      I …just… :((

      B Offline
      B Offline
      Brisingr Aerowing
      wrote on last edited by
      #2

      :(( :(( :(( :((

      public class SysAdmin : Employee
      {

       public override void DoWork(IWorkItem workItem)
       {
            if (workItem.User.Type == UserType.NoLearn){
               throw new NoIWillNotFixYourComputerException(new Luser(workItem.User));
            }else{
                 base.DoWork(workItem);
            }
       }
      

      }

      C 1 Reply Last reply
      0
      • B Brisingr Aerowing

        :(( :(( :(( :((

        public class SysAdmin : Employee
        {

         public override void DoWork(IWorkItem workItem)
         {
              if (workItem.User.Type == UserType.NoLearn){
                 throw new NoIWillNotFixYourComputerException(new Luser(workItem.User));
              }else{
                   base.DoWork(workItem);
              }
         }
        

        }

        C Offline
        C Offline
        crazedDotNetDev
        wrote on last edited by
        #3

        :laugh: And I’ll probably get confronted for changing it. (I’m the new guy in the group.) I think I’ll adopt a new saying: if you don’t respect my genius then you’ll fear my delete key!

        S 1 Reply Last reply
        0
        • C crazedDotNetDev

          :laugh: And I’ll probably get confronted for changing it. (I’m the new guy in the group.) I think I’ll adopt a new saying: if you don’t respect my genius then you’ll fear my delete key!

          S Offline
          S Offline
          Sentenryu
          wrote on last edited by
          #4

          sorry, i wanted to give you a 5, but clicked on the 4, so.. please, post again so i can give you another 5 ;P

          I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

          C 1 Reply Last reply
          0
          • S Sentenryu

            sorry, i wanted to give you a 5, but clicked on the 4, so.. please, post again so i can give you another 5 ;P

            I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

            C Offline
            C Offline
            crazedDotNetDev
            wrote on last edited by
            #5

            no problem

            1 Reply Last reply
            0
            • C crazedDotNetDev

              I want to throw my computer off the roof. I'm modifying a 700+ line stored procedure and this is done a dozen+ times.

              ( CASE WHEN [SomeID] IN ( [batch of hardcoded, unique ids] )
              THEN [hardcoded enum]
              ELSE ( CASE WHEN [SomeID] IN ( [batch of hardcoded, unique ids] )
              THEN [hardcoded enum]
              ELSE ( CASE WHEN [SomeID] IN ( [batch of hardcoded, unique ids] )
              THEN [hardcoded enum]
              ELSE …etc…
              END )
              END )
              END )

              I …just… :((

              K Offline
              K Offline
              KP Lee
              wrote on last edited by
              #6

              I just posted "Really???" talking about a 790 line sproc. At least the original author seems to never have heard of CASE before. :laugh: I'm hoping the batches and enums were different each time. :) (doesn't make it any better.) I'm not a fan of CASE, but I've just hit two updates in a row with minor changes that could be handled better with a few well placed CASE statements. Peppered throughout this, it joins a field with 6 function calls to a passed tabular type, then to make extra sure, (s)he put in a matching where clause. I'm thinking that's 1.2 million function calls if there are 10K records in the table and 100 records in the passed table. Nope, it's only 600+K records. The join being mostly false, the WHERE will never be hit. Anyway, I'm a new hire too. Expect some flack as well. If you're curious, see if what I posted beats your's. I think it did.

              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