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.
What you experience is by design:
The alternatives are to either:
WTFtable, and rely on the behavior to create it automaticallyUse the existing code, but change the
SELECT INTOinto an INSERT:Mind that when using
TOP, you should be defining anORDER BYclause to ensure data is returned consistently.