A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
It is difficult to say how to solve the issue, since I have no idea of what you want to achieve.
Of course one way get rid of the error message is to create a table x with the columns you have in the query. Then at least the query would compile.
I note that you use x as an alias for the UNION ALL query. Maybe you intended to be something recursive. In that case, this might be the query
WITH x AS (
SELECT Po.FamilyId,
Po2.GroupId,
CONCAT( Po.PortionKey, Po2.PortionKey) AS PortionKey,
CONCAT(PNK.PortionKey, PNK.PortionKey) AS PartNumber
FROM extractreports.dbo.GetFinalResultParts Po WITH(NOLOCK)
INNER JOIN extractreports.dbo.GetFinalResultParts Po2 WITH(NOLOCK)
ON Po.GlobalPnId = Po2.GlobalPnId
AND Po2.GroupId = 2
INNER JOIN extractreports.dbo.GetFinalResultMasks PNK WITH(NOLOCK)
ON Po.GlobalPnId = PNK.GlobalPnId
AND PNK.GroupId = 2
AND Po.GroupId = 1
UNION ALL
SELECT t.FamilyId,
Po2.GroupId,
CONCAT(t.PortionKey, Po2.PortionKey) AS PortionKey,
CONCAT(t.PortionKey,PNK.PortionKey ) AS PartNumber
FROM x t with(nolock)
INNER JOIN extractreports.dbo.GetFinalResultParts Po2 WITH(NOLOCK)
ON Po2.GlobalPnId = t.GlobalPnId
AND Po2.GroupId = t.GroupId+ 1
INNER JOIN extractreports.dbo.GetFinalResultMasks PNK WITH(NOLOCK)
ON PNK.GlobalPnId = t.GlobalPnId
AND PNK.GroupId = t.GroupId+ 1
)
SELECT *
INTO extractreports.dbo.getfinalpcMasks
FROM x
But this is a complete speculation on my side.