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. Dysfunctional programming?

Dysfunctional programming?

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasesql-serversysadminquestion
11 Posts 10 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.
  • P PIEBALDconsult

    SQL Server at its best. Guess the output:

    CREATE FUNCTION dbo.WTE ( @ID UNIQUEIDENTIFIER )
    RETURNS TABLE AS RETURN
    (
    SELECT @ID [ID]
    UNION ALL
    SELECT @ID
    UNION ALL
    SELECT @ID
    )
    GO

    DECLARE @ID UNIQUEIDENTIFIER = NEWID()
    SELECT [ID] FROM dbo.WTE ( @ID )

    SELECT [ID] FROM dbo.WTE ( NEWID() )

    DROP FUNCTION dbo.WTE

    This wasted a few hours today.

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

    Knowing absolutely nothing about SQL, I have no idea, although I guess the output was not what was expected (and possibly wasn't even logical, having heard various stories about SQL Server).

    What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???

    1 Reply Last reply
    0
    • P PIEBALDconsult

      SQL Server at its best. Guess the output:

      CREATE FUNCTION dbo.WTE ( @ID UNIQUEIDENTIFIER )
      RETURNS TABLE AS RETURN
      (
      SELECT @ID [ID]
      UNION ALL
      SELECT @ID
      UNION ALL
      SELECT @ID
      )
      GO

      DECLARE @ID UNIQUEIDENTIFIER = NEWID()
      SELECT [ID] FROM dbo.WTE ( @ID )

      SELECT [ID] FROM dbo.WTE ( NEWID() )

      DROP FUNCTION dbo.WTE

      This wasted a few hours today.

      T Offline
      T Offline
      Tomas Takac
      wrote on last edited by
      #3

      Wow! Never seen this before. I tested with RAND() and FLOAT and it's the same behavior. Did you find any explanation?

      1 Reply Last reply
      0
      • P PIEBALDconsult

        SQL Server at its best. Guess the output:

        CREATE FUNCTION dbo.WTE ( @ID UNIQUEIDENTIFIER )
        RETURNS TABLE AS RETURN
        (
        SELECT @ID [ID]
        UNION ALL
        SELECT @ID
        UNION ALL
        SELECT @ID
        )
        GO

        DECLARE @ID UNIQUEIDENTIFIER = NEWID()
        SELECT [ID] FROM dbo.WTE ( @ID )

        SELECT [ID] FROM dbo.WTE ( NEWID() )

        DROP FUNCTION dbo.WTE

        This wasted a few hours today.

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #4

        Interesting. I wouldn't have guessed that! I'd suggest that's worth a quick tip (and possibly a list of what it does in various versions?) For the record, I tried it in SQL Server 2012:

        Microsoft SQL Server 2012 - 11.0.5343.0 (X64)
        May 4 2015 19:11:32
        Copyright (c) Microsoft Corporation
        Express Edition (64-bit) on Windows NT 6.3 <X64> (Build 10586: )

        And

        Microsoft SQL Server 2012 (SP1) - 11.0.3156.0 (X64)
        May 4 2015 18:48:09
        Copyright (c) Microsoft Corporation
        Web Edition (64-bit) on Windows NT 6.2 (Build 9200: ) (Hypervisor)

        And got the same results

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • P PIEBALDconsult

          SQL Server at its best. Guess the output:

          CREATE FUNCTION dbo.WTE ( @ID UNIQUEIDENTIFIER )
          RETURNS TABLE AS RETURN
          (
          SELECT @ID [ID]
          UNION ALL
          SELECT @ID
          UNION ALL
          SELECT @ID
          )
          GO

          DECLARE @ID UNIQUEIDENTIFIER = NEWID()
          SELECT [ID] FROM dbo.WTE ( @ID )

          SELECT [ID] FROM dbo.WTE ( NEWID() )

          DROP FUNCTION dbo.WTE

          This wasted a few hours today.

          S Offline
          S Offline
          Super Lloyd
          wrote on last edited by
          #5

          Now, that is weird and wonderful! :-o I wonder what else I can do with that... :laugh: :rolleyes:

          All in one Menu-Ribbon Bar DirectX for WinRT/C# since 2013! Taking over the world since 1371!

          1 Reply Last reply
          0
          • P PIEBALDconsult

            SQL Server at its best. Guess the output:

            CREATE FUNCTION dbo.WTE ( @ID UNIQUEIDENTIFIER )
            RETURNS TABLE AS RETURN
            (
            SELECT @ID [ID]
            UNION ALL
            SELECT @ID
            UNION ALL
            SELECT @ID
            )
            GO

            DECLARE @ID UNIQUEIDENTIFIER = NEWID()
            SELECT [ID] FROM dbo.WTE ( @ID )

            SELECT [ID] FROM dbo.WTE ( NEWID() )

            DROP FUNCTION dbo.WTE

            This wasted a few hours today.

            N Offline
            N Offline
            Nathan Minier
            wrote on last edited by
            #6

            Function pointers FTW

            "There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli

            1 Reply Last reply
            0
            • P PIEBALDconsult

              SQL Server at its best. Guess the output:

              CREATE FUNCTION dbo.WTE ( @ID UNIQUEIDENTIFIER )
              RETURNS TABLE AS RETURN
              (
              SELECT @ID [ID]
              UNION ALL
              SELECT @ID
              UNION ALL
              SELECT @ID
              )
              GO

              DECLARE @ID UNIQUEIDENTIFIER = NEWID()
              SELECT [ID] FROM dbo.WTE ( @ID )

              SELECT [ID] FROM dbo.WTE ( NEWID() )

              DROP FUNCTION dbo.WTE

              This wasted a few hours today.

              R Offline
              R Offline
              Rob Grainger
              wrote on last edited by
              #7

              Wow, that is truly horrible. I'd describe that as a bug, pure and simple.

              "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

              1 Reply Last reply
              0
              • P PIEBALDconsult

                SQL Server at its best. Guess the output:

                CREATE FUNCTION dbo.WTE ( @ID UNIQUEIDENTIFIER )
                RETURNS TABLE AS RETURN
                (
                SELECT @ID [ID]
                UNION ALL
                SELECT @ID
                UNION ALL
                SELECT @ID
                )
                GO

                DECLARE @ID UNIQUEIDENTIFIER = NEWID()
                SELECT [ID] FROM dbo.WTE ( @ID )

                SELECT [ID] FROM dbo.WTE ( NEWID() )

                DROP FUNCTION dbo.WTE

                This wasted a few hours today.

                S Offline
                S Offline
                Snorri Kristjansson
                wrote on last edited by
                #8

                This is crazy - how is this possible! It's as if the NEWID() call is passed as a paremeter into the function and called three times?????

                1 Reply Last reply
                0
                • P PIEBALDconsult

                  SQL Server at its best. Guess the output:

                  CREATE FUNCTION dbo.WTE ( @ID UNIQUEIDENTIFIER )
                  RETURNS TABLE AS RETURN
                  (
                  SELECT @ID [ID]
                  UNION ALL
                  SELECT @ID
                  UNION ALL
                  SELECT @ID
                  )
                  GO

                  DECLARE @ID UNIQUEIDENTIFIER = NEWID()
                  SELECT [ID] FROM dbo.WTE ( @ID )

                  SELECT [ID] FROM dbo.WTE ( NEWID() )

                  DROP FUNCTION dbo.WTE

                  This wasted a few hours today.

                  J Offline
                  J Offline
                  j peavey
                  wrote on last edited by
                  #9

                  That function should be called WTF....

                  P 1 Reply Last reply
                  0
                  • J j peavey

                    That function should be called WTF....

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #10

                    Not on CP.

                    1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      SQL Server at its best. Guess the output:

                      CREATE FUNCTION dbo.WTE ( @ID UNIQUEIDENTIFIER )
                      RETURNS TABLE AS RETURN
                      (
                      SELECT @ID [ID]
                      UNION ALL
                      SELECT @ID
                      UNION ALL
                      SELECT @ID
                      )
                      GO

                      DECLARE @ID UNIQUEIDENTIFIER = NEWID()
                      SELECT [ID] FROM dbo.WTE ( @ID )

                      SELECT [ID] FROM dbo.WTE ( NEWID() )

                      DROP FUNCTION dbo.WTE

                      This wasted a few hours today.

                      N Offline
                      N Offline
                      Nitin S
                      wrote on last edited by
                      #11

                      this deserves a trophy

                      ===================================================== The grass is always greener on the other side of the fence

                      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