• Kevin Gill (1/15/2010)


    To my mind, this question could/should have been moderated and edited to make it clearer.

    Even though I would have got it wrong had it actually been asking what I thought it was, the fact that it was pretty badly written added an additional, unnecessary level of misdirection that just gets in the way.

    The 'correct' answer does not in itself actually answer the question - I have no more idea now than I had ten minutes ago whether table VARIABLES in SQL2K5 can be set to NULL, even though I did actually know that you can't have table parameters in SQL 2K5 (as they would have solved a lot of my problems last year). I skimmed the answers, thought 'I know SQL2K5 can have table variables' (I admit - misreading on my part but I assumed that if it was a 'trick' question then that answer would refer to all parts of the question equally, given that there's only single word answers for the other options) and gave some thought to whether a table VARIABLE can be set to NULL or not. I made my choice, got it wrong, but didn't actually find out the answer.

    So can table variables be set to NULL? Perhaps this could be added to the explanation...

    declare @TestTab table (TableID int, TableData varchar(32));

    set @TestTab = null;

    Result:

    Msg 137, Level 15, State 1, Line 2

    Must declare the scalar variable "@TestTab".