Implicit Conversion

  • Comments posted to this topic are about the item Implicit Conversion

  • Does it? Not 2 rows 1 and 2?

    Sorry, of course it does, looking at the second sample not the first...

  • Interesting. The subtle difference between the two code samples provided makes all the difference on this one.

  • A simple one to start the week and get my brain going again is appreciated. Thanks.

  • This one wasn't simple for me. It takes a keen eye and some focused thought to get it right. I failed.

    Thanks for the good question.

  • Should have paid more attention to the QotD title.

  • Nice. I let the table def blind me to the facts. 😀

  • Without necessarily knowing anything about the conversions involved, you can see that the data being added comes from a single INSERT statement, where the input data is the union of three result sets each containing one distinct row .

    Either the INSERT statement succeeds and inserts three rows, or fails with an error and inserts none.

    But 3 is not offered as a possible answer, so it must cause an error and insert no rows.

  • archie flockhart (5/31/2016)


    Without necessarily knowing anything about the conversions involved, you can see that the data being added comes from a single INSERT statement, where the input data is the union of three result sets each containing one distinct row .

    Either the INSERT statement succeeds and inserts three rows, or fails with an error and inserts none.

    But 3 is not offered as a possible answer, so it must cause an error and insert no rows.

    Except that the select at the bottom is DISTINCT ID, and the script inserts ID 1 once and ID 2 twice. So if the conversion worked, the correct answer would still be 2 not 3.

  • Yes you're right - which makes it a better and subtler question than I had thought.

  • archie flockhart (5/31/2016)


    Yes you're right - which makes it a better and subtler question than I had thought.

    + 1

    Thank you, Sasidhar!

  • archie flockhart (5/31/2016)


    Yes you're right - which makes it a better and subtler question than I had thought.

    Indeed. It made me fixate on this point and select 2 as the answer - wrong!! :crazy:

  • conversion type errors are display ..,

    Actually in third part they give value 456

    but if we give out put as varchar type '456' mean error wont showing.

    eg:

    DECLARE @tbl TABLE ( id INT, Name VARCHAR(5) );

    INSERT INTO @tbl

    SELECT

    1 AS Id

    , 'ABC' AS Alphabets

    UNION

    SELECT

    2

    , 'XYZ'

    UNION

    SELECT

    2

    , '456';

    SELECT DISTINCT

    id

    FROM

    @tbl;

Viewing 13 posts - 1 through 12 (of 12 total)

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