• Like others, I answered A because it returned "the expected output": NULL. Option C returns an error:

    Msg 208, Level 16, State 1, Line 1

    Invalid object name 'dbo.Employees'.

    I didn't put in the name of a valid table name in my database because that was not a part of the question. The question had the following as a "prequel" to all three of the queries:

    declare @tablevariable varchar(100)

    set @tablevariable = 'Employees'

    So, for option C, I executed

    declare @tablevariable varchar(100)

    set @tablevariable = 'Employees'

    DECLARE @sql nvarchar(4000), @params nvarchar(4000), @count int

    SELECT @sql = N' SELECT @cnt = COUNT(*) FROM dbo.' + quotename(@tablevariable)

    SELECT @params = N'@cnt int OUTPUT'

    EXEC sp_executesql @sql, @params, @cnt = @count OUTPUT select @count

    Therefore, option A returns the expected result (since the table variable is empty) and should be a correct answer.


    Steve Eckhart