T-SQL Table Variable Creating PHYSICAL Table!

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-10T20:39:18Z Indexed on 2010/03/18 15:01 UTC
Read the original article Hit count: 337

Filed under:
|
|

OMG! What am I doing wrong?

declare @WTF TABLE (
 OrderItemId int
)

SELECT TOP 20 OrderItemId as OrderItemId INTO [@WTF] FROM ac_OrderItems

SELECT * FROM [@WTF]

Problem A: This creates a PHYSICAL table called @WTF. WHY?? I thought this was in memory only?!

Problem B: The last line of code, if I do select * from @WTF... WITHOUT the [ ], it returns NOTHING. What is the significance of the [ ]?

I need serious help. I'm losing my MIND!

Thanks in advance.

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql