• mister.magoo (11/16/2010)


    Thanks to those of you who appreciate this question.

    To those who think it had unnecessary "tricks" in it, I did try several variants of this question and they all ended up being too easy.

    The "tricks" were deliberate and designed to check whether you would notice the implicit conversion and whether you even knew it would happen.

    Heh I saw this

    DECLARE @sortby VARCHAR(10)

    SET @sortby='String2'

    SELECT String1, String2, Date1

    FROM (

    SELECT 'StringValue1', '2', CONVERT(datetime,'1 July 2010 00:01:00')

    UNION ALL

    SELECT 'StringValue2', '1', CONVERT(datetime,'2 July 2010 00:02:00')

    )

    Realized that there weren't field names for the various portions of the select and assumed it would error out.

    I didn't see this at the end of the above portion of the query

    AS a(String1,String2,Date1)

    as a practice I've always named my columns in a sub-select/union type situation and expected an error similar to

    Msg 8155, Level 16, State 2, Line 9

    No column name was specified for column 1 of

    So I got it right, but for the wrong reason. :/



    --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]