• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Sql server 2008 idiosyncrasy

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Sql server 2008 idiosyncrasy

    This SQL works in SQL 2000

    SELECT LogId, * FROM Logs
    Order by LogId DESC

    This fails in SQL 2008 with the error message

    Ambiguous column name 'LogId'.

    How ridiculous ? Luckily not affected too much but this could have easily meant a big migration headache.
    Vote Corbyn ! Save this country !

    #2
    Originally posted by fullyautomatix View Post
    This SQL works in SQL 2000

    SELECT LogId, * FROM Logs
    Order by LogId DESC

    This fails in SQL 2008 with the error message

    Ambiguous column name 'LogId'.

    How ridiculous ? Luckily not affected too much but this could have easily meant a big migration headache.
    You're selecting [LogID] twice (once in the *) so it doesn't know which one to sort by.

    Comment


      #3
      Originally posted by PerlOfWisdom View Post
      You're selecting [LogID] twice (once in the *) so it doesn't know which one to sort by.
      Correct. Either alias the column or use Orderby 1 desc

      Assuming that does work T-SQL.
      McCoy: "Medical men are trained in logic."
      Spock: "Trained? Judging from you, I would have guessed it was trial and error."

      Comment


        #4
        Originally posted by lilelvis2000 View Post
        Assuming that does work T-SQL.
        It does


        Originally posted by fullyautomatix View Post
        This SQL works in SQL 2000

        SELECT LogId, * FROM Logs
        Order by LogId DESC

        This fails in SQL 2008 with the error message

        Ambiguous column name 'LogId'.

        How ridiculous ? Luckily not affected too much but this could have easily meant a big migration headache.
        This is another reason why "select *" should NOT be used anywhere near production! Microsoft themselves advise against it.
        Coffee's for closers

        Comment


          #5
          Originally posted by Spacecadet View Post
          This is another reason why "select *" should NOT be used anywhere near production! Microsoft themselves advise against it.
          Surely there's nothing wrong with the "select *". It's using select * and a column by name that doesn't make any sense and shouldn't suprise anyone that the behaviour might vary. Even I know that with my very limited SQL ability.
          Will work inside IR35. Or for food.

          Comment


            #6
            Originally posted by fullyautomatix View Post
            This SQL works in SQL 2000

            SELECT LogId, * FROM Logs
            Order by LogId DESC

            This fails in SQL 2008 with the error message

            Ambiguous column name 'LogId'.

            How ridiculous ? Luckily not affected too much but this could have easily meant a big migration headache.
            The SELECT LogId is redundant as you are doing a SELECT *.

            Comment


              #7
              Originally posted by VectraMan View Post
              Surely there's nothing wrong with the "select *". It's using select * and a column by name that doesn't make any sense and shouldn't suprise anyone that the behaviour might vary. Even I know that with my very limited SQL ability.
              problem with using select * is that if anything changes to the table you're selecting from then your SQL is still valid when it should more than likely be invalid.
              Coffee's for closers

              Comment


                #8
                Originally posted by kandr View Post
                The SELECT LogId is redundant as you are doing a SELECT *.
                The reason for using it would be to see the whole table but with the field of interest on the left. This would never be used programatically.

                Comment


                  #9
                  Using * can also cause a creep in performance degradation as more columns get added to a table over time.

                  Comment


                    #10
                    Originally posted by jmo21 View Post
                    Using * can also cause a creep in performance degradation as more columns get added to a table over time.
                    It causes a performance degradation from the start. * is shorthand for 'look up what the table cols are in the system tables'.
                    +50 Xeno Geek Points
                    Come back Toolpusher, scotspine, Voodooflux. Pogle
                    As for the rest of you - DILLIGAF

                    Purveyor of fine quality smut since 2005

                    CUK Olympic University Challenge Champions 2010/2012

                    Comment

                    Working...
                    X