Share via

when run this query get error invalid object x ?

ahmed salah 3,216 Reputation points
2021-06-12T11:25:34.703+00:00

I run recursive but i face error it give me invalid object x
so How to solve issue

SELECT *
  INTO extractreports.dbo.getfinalpcMasks
  FROM (SELECT 
               Po.FamilyId,
               Po2.GroupId,           
               CONCAT( Po.PortionKey, 

                                 Po2.PortionKey )
                        PortionKey
                        , CONCAT(PNK.PortionKey 

                                , PNK.PortionKey)
                       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) 
                              PortionKey

                            ,  CONCAT(t.PortionKey,PNK.PortionKey ) 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

        ) x

so how to solve issue please ?

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

Answer accepted by question author

Erland Sommarskog 134.7K Reputation points MVP Volunteer Moderator
2021-06-12T11:44:59.073+00:00

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.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.