You can use a subquery - see the example below:CREATE TABLE #tmp(colA INT, colB INT);
INSERT INTO #tmp VALUES (1,10),(2,15),(3,17);
--
SELECT * FROM
#tmp
PIVOT (MAX(colb) FOR cola IN ([1],[2],[3]))P
-- same thing as above, except it is pivoting results of a subquery
SELECT * FROM
(
SELECT colb,cola FROM #tmp
)s
PIVOT (MAX(colb) FOR cola IN ([1],[2],[3]))P
DROP TABLE #tmp
Or did you mean something like a correlated subquery? If so can you post the code?