BETWEEN

  • rmechaber (3/5/2012)


    This was a terribly difficult question: I spent 10 minutes looking for the syntax error, catch, gotcha, trip-up, etc., only to submit the straightforward, correct answer.:-D

    Rich

    Same thing here... I looked at it went... "All of them" then went "It's a QOTD, it can't be that straightforward"... spent a while analyzing it... Finally shrugged and went with my initial answer. Yayz



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • Great back to basics question. What a way to start my Monday morning, thanks Steve I needed this! :w00t: I use the between keyword quite a bit these day.



    Everything is awesome!

  • Very good question to test the basics

    M&M

  • Nice and straight forward. Thanks for the question Steve!

  • I was throw off with the drop script at the end. Overanalyzing the question.

  • Thanks Steve

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Thanks Steve, nice and easy one. I had to dig into documentation to remember if BETWEEN included endpoints or not.

    "El" Jerry.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

  • rmechaber (3/5/2012)


    This was a terribly difficult question: I spent 10 minutes looking for the syntax error, catch, gotcha, trip-up, etc., only to submit the straightforward, correct answer.:-D

    Rich

    I did the same. Getting a little gun shy....

    Rob Schripsema
    Propack, Inc.

  • Great question!

    Thanks Steve

  • I got it right, but i managed myself by a sql-query from a c# code that was using date comparison without casting string-dates to sql-dates and it worked well. I thought it's some trick.

    Regards

    IM

    Igor Micev,My blog: www.igormicev.com

  • Easy question, good for a Monday when starting a new job.

  • That was a nice simple no tricks (and very easy) question. Thanks, Steve.

    Tom

  • cengland0 (3/5/2012)


    Then, the between was comparing string values. I had to guess that it would automatically convert those to date.

    Guess??!! But BETWEEN is an operator requiring 3 arguments of the same type; if the types aren't all the same it tries implicit conversion to the type with highest precedence; date has higher precedence than varchar; so there was no need to guess.

    To make things worse, it was using the date in yyyy/mm/dd format (or was it?). All those dates would still be valid in yyyy/dd/mm format too. What date collation was set on the server? Who knows.

    Who knows??!! And who cares, as it makes no difference to the answer - whether YMD or YDM those six dates are in ascending order, so they are all "between" the first one and the last one.

    Tom

  • I too was looking for the catch for a while and then decided there was none. Nice, basic question. Thanks



    Posting Data Etiquette - Jeff Moden[/url]
    Posting Performance Based Questions - Gail Shaw[/url]
    Hidden RBAR - Jeff Moden[/url]
    Cross Tabs and Pivots - Jeff Moden[/url]
    Catch-all queries - Gail Shaw[/url]


    If you don't have time to do it right, when will you have time to do it over?

  • L' Eomot Inversé (3/5/2012)


    cengland0 (3/5/2012)


    Then, the between was comparing string values. I had to guess that it would automatically convert those to date.

    Guess??!! But BETWEEN is an operator requiring 3 arguments of the same type; if the types aren't all the same it tries implicit conversion to the type with highest precedence; date has higher precedence than varchar; so there was no need to guess.

    Exactly! This was the challenge for me. I didn't know about the implicit conversion to date and I didn't know the precedence of those conversions.

Viewing 15 posts - 16 through 30 (of 49 total)

You must be logged in to reply to this topic. Login to reply