samedi 25 avril 2015

Mismatch of columns in UNION ALL statement

I have this query,

            QRY = "(SELECT " +
            "[NAME]," + 
            "[NAME] AS RESULT, " +
            //"NULL AS TYPE," + 
            "' - ' AS VALUE, " + 
            "0 AS ORDERING " +
            "FROM " +
            "[PARTY_MSTR] " +
            "UNION ALL " +
            "SELECT " +
            "[PARTY_MSTR].[NAME], " +
            "'  - ' || [T1].[T_NAME], " + 
            "(SELECT [T2].[T_NAME]," + 
            "SUM(COALESCE([T2].[VALUE1], 0)) " +  FROM [T2] " + 
            "CROSS JOIN [T1] ON [T1].[T_NAME] = [T2].[T_NAME] " + 
            "GROUP BY [T2].[T_NAME]), " + 
            "1 " +
            "FROM " +
            "[PARTY_MSTR] " +
            "CROSS JOIN [T1] " +
            ") AS X";

When I run this query, I got this error SELECTs to the left and right of UNION ALL do not have the same number of result columns

Now I remove the comments, and the second error comes, only a single result allowed for a SELECT that is part of an expression. What's wrong with this queries.? I am using SQLite database.

Aucun commentaire:

Enregistrer un commentaire