• Sorry,

    I have to agree with Lynn.

    If you don't have a table named employees, then of course it won't work.

    Copying and pasting the query code into SSMS and running it is the cheap way out.

    Knowing you don't have a table named employees in whatever scratch database you have, substituting in the table name in the beginning of the question with one you do have in your test database would let you test it properly.

    set @tablevariable = 'Employees'

    Notice the beginning of the question.

    Sam has to run a query dynamically & get the count in a variable and do some processing based on the count. Which of the following queries will return expected output?

    If you just wanted to run the query, you'd need to substitute in a table in place of the employees one that Sam apparently has.



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