Exists

  • Comments posted to this topic are about the item Exists

  • Good question, but try:

    SELECT 'Test' WHERE EXISTS (SELECT LOG(0))

    TSQL is not a model of consistency.

  • Good Question thanks 🙂

  • SQLkiwi (8/2/2011)


    Good question, but try:

    SELECT 'Test' WHERE EXISTS (SELECT LOG(0))

    TSQL is not a model of consistency.

    Even for the below statement also

    SELECT 'Test' WHERE EXISTS (SELECT SQRT(-1))

  • deepak.a (8/2/2011)


    Even for the below statement also

    SELECT 'Test' WHERE EXISTS (SELECT SQRT(-1))

    Some more:

    SELECT 'Test' WHERE EXISTS (SELECT ACOS(PI()))

    SELECT 'Test' WHERE EXISTS (SELECT ASIN(PI()))

    SELECT 'Test' WHERE EXISTS (SELECT LOG10(0))

  • Thanks for the question

    M&M

  • Good question

    -----------------
    Gobikannan

  • Interesting question, thanks!

    /@devandreas

  • I didn't like the "explanation".

    What I am missing is the real explanation why the sub query in the EXISTS doesn't result in an error.

    It actually matters what is in that sub query. For example:

    SELECT 'Test' WHERE EXISTS (SELECT 1 WHERE 1 = 0)

    will not return anything.

  • Interesting question, and something definitely to be aware of.

    Thanks

    _____________________________________________________________________
    [font="Comic Sans MS"]"The difficult tasks we do immediately, the impossible takes a little longer"[/font]

  • EXISTS check if subquery returns ROWS and does not execute EXPRESSION or read column value. So, in this case divide by zero is never executed, but ONE ROW exists.

  • DugyC (8/3/2011)


    Interesting question, and something definitely to be aware of.

    Thanks

    I'm not convinved that I need to be aware of this.

    Interesting question though.

  • paul s-306273 (8/3/2011)


    DugyC (8/3/2011)


    Interesting question, and something definitely to be aware of.

    Thanks

    I'm not convinved that I need to be aware of this.

    Interesting question though.

    I agree with you.

  • So if Microsoft are correct to claim that this is by design, then presumably they would acknowledge all the counter-examples provided by SQLkiwi as bugs?

    P.S. I wonder how many of the 60% who got this right did so without running the code!

  • I'm not convinced that EXPRESSION is not executed

    Try this:

    SELECT 'TEST'

    WHERE EXISTS (SELECT 1/0 WHERE 1/0 =1)

Viewing 15 posts - 1 through 15 (of 43 total)

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