Is there a tip to use t more than in time?
Of course, if you do this in a stored procedure, just upload it to the #temp table. At the end of the stored procedure, the #temp table disappears.
with t as ( select row_number() OVER (partition by ID ORDER BY id) as numb, * from my_table where id= 6 ) select * into
Outside of SP, just make sure you drop the # table before trying to create it again, otherwise the next select ..into #name will fail with the error #name already exists
source share