Output type of following query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shilpa george
    New Member
    • Oct 2011
    • 15

    Output type of following query

    Hello,
    I have an sql query as following. Could you please tell me how the right function works? When the date is given in quotes
    right('1990-05-23',5) returns 05-23
    otherwise
    right(1990-05-23,5) returns 1990...could you please help with this?
    Also,the query returns 0.

    select right('1990-05-23',5)<right('1 995-02-03',5)
    In sql does 0 represent a true or false?

    Thank you in advance
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Right returns the x number of characters of a string starting from the right most character.

    What you have in your first example is a string, not a date.

    Your second example isn't even returning the correct result. It should 1962. Because without quotes, what it is is 1990 minus 5 minus 23, which is 1962. Which is then converted to a string '1962', and then the right 5 characters are returned which is '1962'. If you are getting 1990 instead of 1962, then either you posted the wrong SQL or something else is wrong.

    Your third example shouldn't even run, it should error out.

    None of the queries you posted would return 0. SQL has no concept of true or false. That is a human construct and is up to you to determine. But the norm is to use 0 as false.

    Comment

    • shilpa george
      New Member
      • Oct 2011
      • 15

      #3
      Thank u Sir
      As you have said the second example,
      select right(1990-05-23,5) returns 1962..
      But the third example
      select right('1990-05-23',5)<right('1 995-02-03',5)
      returns 0
      and when given as
      select right('1990-05-23',5)>right('1 995-02-03',5)
      returns 1
      I have provided the same query as I have used still I am getting this output.... I am using MySQL Front as database...
      Could you please tell me how this comparison is done?

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You are using MySQL? You posted in the Microsoft SQL forum. In Microsoft SQL, that results in an error. You have to ask your question in the correct forum. But if I had to guess, it takes the right 5 characters of each string and then does a ascii value comparison letter by letter to evaluate which string is "larger".

        Comment

        Working...