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. WTF Was This Guy Thinking!!! [modified]

WTF Was This Guy Thinking!!! [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasecsharpsql-serversysadminhelp
16 Posts 13 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.
  • A Andrew Rissing

    With a bit of formatting, it makes 'more' sense:

    IIf
    (TX.TX_TYPE="R",
    IIf
    (TX.TX_MOSTYPE="P",
    IIf
    (TX.TX_DEST_STATUS="A",
    "PO Receipt",
    IIf
    (TX.TX_DEST_STATUS="U",
    "PO Receipt Hold",
    "Other"
    )
    ),
    IIf
    (TX.TX_DEST_STATUS="A",
    "WIP Receipt",
    IIf
    (TX.TX_DEST_STATUS="U",
    "WIP Hold",
    "Other"
    )
    )
    ),
    IIf
    (TX.TX_TYPE="I",
    IIf
    (ISNULL(RTRIM(TX.TX_MOSJOB)) Or RTRIM(TX.TX_MOSJOB)="",
    "Shipment Return",
    "Reverse Issue"
    ),
    IIf
    (TX.TX_ORIGIN_STATUS=TX.TX_DEST_STATUS,
    "Loc Transfer",
    IIf(TX.TX_ORIGIN="SCRAPPED",
    "Reverse Scrap",
    IIf
    (TX.TX_ORIGIN_STATUS="J",
    "Count Adj Up",
    IIf
    (TX.TX_ORIGIN_STATUS="D",
    "PN Change To",
    IIf
    (TX.TX_ORIGIN_STATUS="I",
    "Reverse Unplanned Issue",
    IIf
    (TX.TX_ORIGIN_STATUS="A" And TX.TX_DEST_STATUS="U",
    "Hold",
    IIf
    (TX.TX_ORIGIN_STATUS="U" And TX.TX_DEST_STATUS="A",
    "Off Hold",
    "Other"
    )
    )
    )
    )
    )
    )
    )
    )
    ) AS [Transaction Type]

    Granted, nesting like this just makes it impossible to read without a gratuitous use of formatting. The original query was just not very consistent in its usage of formatting it. The above was the best I could come up with to be able to read it effectively....

    K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #5

    I was able to clean it up a bit more, although it took awhile.

    CASE WHEN TX.TX_TYPE = 'R' AND TX.TX_MOSTYPE = 'P' AND TX.TX_DEST_STATUS = 'A' THEN 'PO Receipt'
    WHEN TX.TX_TYPE = 'R' AND TX.TX_MOSTYPE = 'P' AND TX.TX_DEST_STATUS = 'U' THEN 'PO Receipt Hold'
    WHEN TX.TX_TYPE = 'R' AND TX.TX_MOSTYPE = 'P' THEN 'Other'
    WHEN TX.TX_TYPE = 'R' AND TX.TX_DEST_STATUS = 'A' THEN 'WIP Receipt'
    WHEN TX.TX_TYPE = 'R' AND TX.TX_DEST_STATUS = 'U' THEN 'WIP Hold'
    WHEN TX.TX_TYPE = 'R' THEN 'Other'
    WHEN TX.TX_TYPE = 'I' AND ISNULL(RTRIM(TX.TX_MOSJOB),'') = '' THEN 'Shipment Return'
    WHEN TX.TX_TYPE = 'I' THEN 'Reverse Issue'
    WHEN TX.TX_ORIGIN_STATUS = TX.TX_DEST_STATUS THEN 'Loc Transfer'
    WHEN TX.TX_ORIGIN = 'SCRAPPED' THEN 'Reverse Scrap'
    WHEN TX.TX_ORIGIN_STATUS = 'J' THEN 'Count Adj Up'
    WHEN TX.TX_ORIGIN_STATUS = 'D' THEN 'PN Change To'
    WHEN TX.TX_ORIGIN_STATUS = 'I' THEN 'Reverse Unplanned Issue'
    WHEN TX.TX_ORIGIN_STATUS = 'A' AND TX.TX_DEST_STATUS = 'U' THEN 'Hold'
    WHEN TX.TX_ORIGIN_STATUS = 'U' AND TX.TX_DEST_STATUS = 'A' THEN 'Off Hold' ELSE 'Other'
    END AS Transaction_Type

    Everything makes sense in someone's mind

    D 1 Reply Last reply
    0
    • K Kevin Marois

      I'm converting an MS Access app to C# & SQL Server. Here's part of an Access query I just came across:

      IIf(TX.TX_TYPE="R",
      IIf(TX.TX_MOSTYPE="P",
      IIf(TX.TX_DEST_STATUS="A","PO Receipt",
      IIf(TX.TX_DEST_STATUS="U","PO Receipt Hold","Other")),
      IIf(TX.TX_DEST_STATUS="A","WIP Receipt",
      IIf(TX.TX_DEST_STATUS="U","WIP Hold","Other"))),
      IIf(TX.TX_TYPE="I",IIf(ISNULL(RTRIM(TX.TX_MOSJOB)) Or RTRIM(TX.TX_MOSJOB)="","Shipment Return","Reverse Issue"),
      IIf(TX.TX_ORIGIN_STATUS=TX.TX_DEST_STATUS,"Loc Transfer",
      IIf(TX.TX_ORIGIN="SCRAPPED","Reverse Scrap",
      IIf(TX.TX_ORIGIN_STATUS="J","Count Adj Up",
      IIf(TX.TX_ORIGIN_STATUS="D","PN Change To",
      IIf(TX.TX_ORIGIN_STATUS="I","Reverse Unplanned Issue",
      IIf(TX.TX_ORIGIN_STATUS="A" And TX.TX_DEST_STATUS="U","Hold",
      IIf(TX.TX_ORIGIN_STATUS="U" And TX.TX_DEST_STATUS="A","Off Hold","Other"))))))))) AS [Transaction Type]

      You'll notice that

      TX.TX_DEST_STATUS="A"

      is being evaluated more than once. Go figure

      Everything makes sense in someone's mind

      moved on Thursday, January 28, 2010 7:54 AM

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #6

      It looks like Linq, pre-Linq. ;) Marc

      1 Reply Last reply
      0
      • K Kevin Marois

        I'm converting an MS Access app to C# & SQL Server. Here's part of an Access query I just came across:

        IIf(TX.TX_TYPE="R",
        IIf(TX.TX_MOSTYPE="P",
        IIf(TX.TX_DEST_STATUS="A","PO Receipt",
        IIf(TX.TX_DEST_STATUS="U","PO Receipt Hold","Other")),
        IIf(TX.TX_DEST_STATUS="A","WIP Receipt",
        IIf(TX.TX_DEST_STATUS="U","WIP Hold","Other"))),
        IIf(TX.TX_TYPE="I",IIf(ISNULL(RTRIM(TX.TX_MOSJOB)) Or RTRIM(TX.TX_MOSJOB)="","Shipment Return","Reverse Issue"),
        IIf(TX.TX_ORIGIN_STATUS=TX.TX_DEST_STATUS,"Loc Transfer",
        IIf(TX.TX_ORIGIN="SCRAPPED","Reverse Scrap",
        IIf(TX.TX_ORIGIN_STATUS="J","Count Adj Up",
        IIf(TX.TX_ORIGIN_STATUS="D","PN Change To",
        IIf(TX.TX_ORIGIN_STATUS="I","Reverse Unplanned Issue",
        IIf(TX.TX_ORIGIN_STATUS="A" And TX.TX_DEST_STATUS="U","Hold",
        IIf(TX.TX_ORIGIN_STATUS="U" And TX.TX_DEST_STATUS="A","Off Hold","Other"))))))))) AS [Transaction Type]

        You'll notice that

        TX.TX_DEST_STATUS="A"

        is being evaluated more than once. Go figure

        Everything makes sense in someone's mind

        moved on Thursday, January 28, 2010 7:54 AM

        P Offline
        P Offline
        pawelchooch
        wrote on last edited by
        #7

        I've seen Garbage like this before, it usually happens when engineers pretend to be programmers... I laugh at inappropriate times

        1 Reply Last reply
        0
        • K Kevin Marois

          I'm converting an MS Access app to C# & SQL Server. Here's part of an Access query I just came across:

          IIf(TX.TX_TYPE="R",
          IIf(TX.TX_MOSTYPE="P",
          IIf(TX.TX_DEST_STATUS="A","PO Receipt",
          IIf(TX.TX_DEST_STATUS="U","PO Receipt Hold","Other")),
          IIf(TX.TX_DEST_STATUS="A","WIP Receipt",
          IIf(TX.TX_DEST_STATUS="U","WIP Hold","Other"))),
          IIf(TX.TX_TYPE="I",IIf(ISNULL(RTRIM(TX.TX_MOSJOB)) Or RTRIM(TX.TX_MOSJOB)="","Shipment Return","Reverse Issue"),
          IIf(TX.TX_ORIGIN_STATUS=TX.TX_DEST_STATUS,"Loc Transfer",
          IIf(TX.TX_ORIGIN="SCRAPPED","Reverse Scrap",
          IIf(TX.TX_ORIGIN_STATUS="J","Count Adj Up",
          IIf(TX.TX_ORIGIN_STATUS="D","PN Change To",
          IIf(TX.TX_ORIGIN_STATUS="I","Reverse Unplanned Issue",
          IIf(TX.TX_ORIGIN_STATUS="A" And TX.TX_DEST_STATUS="U","Hold",
          IIf(TX.TX_ORIGIN_STATUS="U" And TX.TX_DEST_STATUS="A","Off Hold","Other"))))))))) AS [Transaction Type]

          You'll notice that

          TX.TX_DEST_STATUS="A"

          is being evaluated more than once. Go figure

          Everything makes sense in someone's mind

          moved on Thursday, January 28, 2010 7:54 AM

          M Offline
          M Offline
          Muneeb R Baig
          wrote on last edited by
          #8

          As you wrote:

          Everything makes sense in someone's mind

          -muneeb A thing of beauty is the joy forever.

          1 Reply Last reply
          0
          • K Kevin Marois

            I'm converting an MS Access app to C# & SQL Server. Here's part of an Access query I just came across:

            IIf(TX.TX_TYPE="R",
            IIf(TX.TX_MOSTYPE="P",
            IIf(TX.TX_DEST_STATUS="A","PO Receipt",
            IIf(TX.TX_DEST_STATUS="U","PO Receipt Hold","Other")),
            IIf(TX.TX_DEST_STATUS="A","WIP Receipt",
            IIf(TX.TX_DEST_STATUS="U","WIP Hold","Other"))),
            IIf(TX.TX_TYPE="I",IIf(ISNULL(RTRIM(TX.TX_MOSJOB)) Or RTRIM(TX.TX_MOSJOB)="","Shipment Return","Reverse Issue"),
            IIf(TX.TX_ORIGIN_STATUS=TX.TX_DEST_STATUS,"Loc Transfer",
            IIf(TX.TX_ORIGIN="SCRAPPED","Reverse Scrap",
            IIf(TX.TX_ORIGIN_STATUS="J","Count Adj Up",
            IIf(TX.TX_ORIGIN_STATUS="D","PN Change To",
            IIf(TX.TX_ORIGIN_STATUS="I","Reverse Unplanned Issue",
            IIf(TX.TX_ORIGIN_STATUS="A" And TX.TX_DEST_STATUS="U","Hold",
            IIf(TX.TX_ORIGIN_STATUS="U" And TX.TX_DEST_STATUS="A","Off Hold","Other"))))))))) AS [Transaction Type]

            You'll notice that

            TX.TX_DEST_STATUS="A"

            is being evaluated more than once. Go figure

            Everything makes sense in someone's mind

            moved on Thursday, January 28, 2010 7:54 AM

            J Offline
            J Offline
            Jorgen Andersson
            wrote on last edited by
            #9

            Looks to me like a repeated event of technically challenged boss entering the room of a stressed halfwit programmer shouting: We need to add this NOW!

            1 Reply Last reply
            0
            • T thrakazog

              I think step 1 is to delete it and then ask what the original intention was.

              G Offline
              G Offline
              GibbleCH
              wrote on last edited by
              #10

              This is where you write a bank of unit tests, based on the input/output of this clause. Then refactor ensuring all tests keep passing.

              1 Reply Last reply
              0
              • K Kevin Marois

                I'm converting an MS Access app to C# & SQL Server. Here's part of an Access query I just came across:

                IIf(TX.TX_TYPE="R",
                IIf(TX.TX_MOSTYPE="P",
                IIf(TX.TX_DEST_STATUS="A","PO Receipt",
                IIf(TX.TX_DEST_STATUS="U","PO Receipt Hold","Other")),
                IIf(TX.TX_DEST_STATUS="A","WIP Receipt",
                IIf(TX.TX_DEST_STATUS="U","WIP Hold","Other"))),
                IIf(TX.TX_TYPE="I",IIf(ISNULL(RTRIM(TX.TX_MOSJOB)) Or RTRIM(TX.TX_MOSJOB)="","Shipment Return","Reverse Issue"),
                IIf(TX.TX_ORIGIN_STATUS=TX.TX_DEST_STATUS,"Loc Transfer",
                IIf(TX.TX_ORIGIN="SCRAPPED","Reverse Scrap",
                IIf(TX.TX_ORIGIN_STATUS="J","Count Adj Up",
                IIf(TX.TX_ORIGIN_STATUS="D","PN Change To",
                IIf(TX.TX_ORIGIN_STATUS="I","Reverse Unplanned Issue",
                IIf(TX.TX_ORIGIN_STATUS="A" And TX.TX_DEST_STATUS="U","Hold",
                IIf(TX.TX_ORIGIN_STATUS="U" And TX.TX_DEST_STATUS="A","Off Hold","Other"))))))))) AS [Transaction Type]

                You'll notice that

                TX.TX_DEST_STATUS="A"

                is being evaluated more than once. Go figure

                Everything makes sense in someone's mind

                moved on Thursday, January 28, 2010 7:54 AM

                I Offline
                I Offline
                IT_Guy 1
                wrote on last edited by
                #11

                Holy sh*t...thats just horrific man. :) as long as I don't encounter that ever! :laugh:

                1 Reply Last reply
                0
                • K Kevin Marois

                  I was able to clean it up a bit more, although it took awhile.

                  CASE WHEN TX.TX_TYPE = 'R' AND TX.TX_MOSTYPE = 'P' AND TX.TX_DEST_STATUS = 'A' THEN 'PO Receipt'
                  WHEN TX.TX_TYPE = 'R' AND TX.TX_MOSTYPE = 'P' AND TX.TX_DEST_STATUS = 'U' THEN 'PO Receipt Hold'
                  WHEN TX.TX_TYPE = 'R' AND TX.TX_MOSTYPE = 'P' THEN 'Other'
                  WHEN TX.TX_TYPE = 'R' AND TX.TX_DEST_STATUS = 'A' THEN 'WIP Receipt'
                  WHEN TX.TX_TYPE = 'R' AND TX.TX_DEST_STATUS = 'U' THEN 'WIP Hold'
                  WHEN TX.TX_TYPE = 'R' THEN 'Other'
                  WHEN TX.TX_TYPE = 'I' AND ISNULL(RTRIM(TX.TX_MOSJOB),'') = '' THEN 'Shipment Return'
                  WHEN TX.TX_TYPE = 'I' THEN 'Reverse Issue'
                  WHEN TX.TX_ORIGIN_STATUS = TX.TX_DEST_STATUS THEN 'Loc Transfer'
                  WHEN TX.TX_ORIGIN = 'SCRAPPED' THEN 'Reverse Scrap'
                  WHEN TX.TX_ORIGIN_STATUS = 'J' THEN 'Count Adj Up'
                  WHEN TX.TX_ORIGIN_STATUS = 'D' THEN 'PN Change To'
                  WHEN TX.TX_ORIGIN_STATUS = 'I' THEN 'Reverse Unplanned Issue'
                  WHEN TX.TX_ORIGIN_STATUS = 'A' AND TX.TX_DEST_STATUS = 'U' THEN 'Hold'
                  WHEN TX.TX_ORIGIN_STATUS = 'U' AND TX.TX_DEST_STATUS = 'A' THEN 'Off Hold' ELSE 'Other'
                  END AS Transaction_Type

                  Everything makes sense in someone's mind

                  D Offline
                  D Offline
                  ddecoy
                  wrote on last edited by
                  #12

                  Nice to see people with some extra time on their hands :-\

                  Learning without thought is labor lost; thought without learning is perilous. (Confucius)

                  1 Reply Last reply
                  0
                  • K Kevin Marois

                    I'm converting an MS Access app to C# & SQL Server. Here's part of an Access query I just came across:

                    IIf(TX.TX_TYPE="R",
                    IIf(TX.TX_MOSTYPE="P",
                    IIf(TX.TX_DEST_STATUS="A","PO Receipt",
                    IIf(TX.TX_DEST_STATUS="U","PO Receipt Hold","Other")),
                    IIf(TX.TX_DEST_STATUS="A","WIP Receipt",
                    IIf(TX.TX_DEST_STATUS="U","WIP Hold","Other"))),
                    IIf(TX.TX_TYPE="I",IIf(ISNULL(RTRIM(TX.TX_MOSJOB)) Or RTRIM(TX.TX_MOSJOB)="","Shipment Return","Reverse Issue"),
                    IIf(TX.TX_ORIGIN_STATUS=TX.TX_DEST_STATUS,"Loc Transfer",
                    IIf(TX.TX_ORIGIN="SCRAPPED","Reverse Scrap",
                    IIf(TX.TX_ORIGIN_STATUS="J","Count Adj Up",
                    IIf(TX.TX_ORIGIN_STATUS="D","PN Change To",
                    IIf(TX.TX_ORIGIN_STATUS="I","Reverse Unplanned Issue",
                    IIf(TX.TX_ORIGIN_STATUS="A" And TX.TX_DEST_STATUS="U","Hold",
                    IIf(TX.TX_ORIGIN_STATUS="U" And TX.TX_DEST_STATUS="A","Off Hold","Other"))))))))) AS [Transaction Type]

                    You'll notice that

                    TX.TX_DEST_STATUS="A"

                    is being evaluated more than once. Go figure

                    Everything makes sense in someone's mind

                    moved on Thursday, January 28, 2010 7:54 AM

                    M Offline
                    M Offline
                    megaadam
                    wrote on last edited by
                    #13

                    This dude is clearly a Lisp-genius, stuck with the wrong programming languge. What a pity!

                    ........................ Life is too shor

                    1 Reply Last reply
                    0
                    • A Andrew Rissing

                      Btw, this looks more like a coding horror than 'wicked code'. ;P

                      S Offline
                      S Offline
                      sashoalm
                      wrote on last edited by
                      #14

                      It's in the coding horrors section. Or was the topic moved later with all the replies? I didn't think it was possible to do so in codeproject.

                      There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

                      A 1 Reply Last reply
                      0
                      • S sashoalm

                        It's in the coding horrors section. Or was the topic moved later with all the replies? I didn't think it was possible to do so in codeproject.

                        There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

                        A Offline
                        A Offline
                        Andrew Rissing
                        wrote on last edited by
                        #15

                        It was moved.

                        1 Reply Last reply
                        0
                        • K Kevin Marois

                          I'm converting an MS Access app to C# & SQL Server. Here's part of an Access query I just came across:

                          IIf(TX.TX_TYPE="R",
                          IIf(TX.TX_MOSTYPE="P",
                          IIf(TX.TX_DEST_STATUS="A","PO Receipt",
                          IIf(TX.TX_DEST_STATUS="U","PO Receipt Hold","Other")),
                          IIf(TX.TX_DEST_STATUS="A","WIP Receipt",
                          IIf(TX.TX_DEST_STATUS="U","WIP Hold","Other"))),
                          IIf(TX.TX_TYPE="I",IIf(ISNULL(RTRIM(TX.TX_MOSJOB)) Or RTRIM(TX.TX_MOSJOB)="","Shipment Return","Reverse Issue"),
                          IIf(TX.TX_ORIGIN_STATUS=TX.TX_DEST_STATUS,"Loc Transfer",
                          IIf(TX.TX_ORIGIN="SCRAPPED","Reverse Scrap",
                          IIf(TX.TX_ORIGIN_STATUS="J","Count Adj Up",
                          IIf(TX.TX_ORIGIN_STATUS="D","PN Change To",
                          IIf(TX.TX_ORIGIN_STATUS="I","Reverse Unplanned Issue",
                          IIf(TX.TX_ORIGIN_STATUS="A" And TX.TX_DEST_STATUS="U","Hold",
                          IIf(TX.TX_ORIGIN_STATUS="U" And TX.TX_DEST_STATUS="A","Off Hold","Other"))))))))) AS [Transaction Type]

                          You'll notice that

                          TX.TX_DEST_STATUS="A"

                          is being evaluated more than once. Go figure

                          Everything makes sense in someone's mind

                          moved on Thursday, January 28, 2010 7:54 AM

                          W Offline
                          W Offline
                          Wamuti
                          wrote on last edited by
                          #16

                          I think he meant to make a Ladder; Only that it's lying on the wrong wall :laugh:

                          Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

                          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