What will happen with below code???

  • Hugo Kornelis

    SSC Guru

    Points: 64685

    roopa.subbareddy (6/14/2015)


    There is no Single quotes in the Select for the phone number. So it must give an error message.

    Try running the code. You'll see that the integer values are silently converted to character without raising an error.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • TomThomson

    SSC Guru

    Points: 104773

    Hany Helmy (6/14/2015)


    Nice tricky question, thanx.

    I thought it was quite a nice question.

    It seemed pretty trick-free to me, although you did have to remember three facts: (i) that UNION is a set operation (unlike UNION ALL, which is a bag operation), (ii) that integers used in a string context are converted automatically to string, and (iii) that 1234512345 is small enough to be representable in the INT type.

    Tom

  • Koen Verbeeck

    SSC Guru

    Points: 258965

    Easy one, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • akljfhnlaflkj

    SSC Guru

    Points: 76202

    An easy one, now that I have learned the difference between UNION and UNION ALL.

Viewing 4 posts - 16 through 19 (of 19 total)

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