How do I accumulate values in T-SQL? AFAIK there is no ARRAY type.
I want to re-use the values in the same query like demonstrated in this PostgreSQL example using array
If you're just collecting some values to reuse, try a table variable rather than a temp table
DECLARE @t TABLE
(
id INT PRIMARY KEY,
name NVARCHAR(100)
)
INSERT @t VALUES (3 , 'John')
-- etc
The table variable is in-memory only, instead of going in the tempdb database like a temp table does.
Check Should I use a #temp table or table variable for more information.