I have a query which retrieves around 184K rows and stores into Temporary table. Now, In second query I am first retrieving all the data from Temporary table and pivoting it. While pivoting I am getting below error.
Msg 1105, Level 17, State 2, Line 56 Could not allocate space for object 'dbo.WORKFILE GROUP large record overflow storage: 140761897762816' in database 'tempdb' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.
SQL Query as below:
SELECT *
FROM
(
SELECT Id,
Name,
ROW_NUMBER() OVER (PARTITION BY Id,
Name
ORDER BY
(
SELECT NULL
)
) AS [Row Number],
[Value]
FROM #Data --184K Rows
) AS S
PIVOT
(
MAX([Value])
FOR Name IN ([A],[B],[C],[D],[E],[F],[G],[H],[I],[J],[K],[L],[M],[N],[O],[P],[Q],[R]
)
) AS PVT;
Can we resolve this issue without increasing the size of tempDB?