Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:10:32+00:00 2026-06-13T01:10:32+00:00

Hello i’ve the following SQL Query which produces the following result SELECT * FROM

  • 0

Hello i’ve the following SQL Query which produces the following result

SELECT * FROM
     (
     Select
        catalogid, numitems, allitems - numitems ignoreditems
     from
         ( 
             select
                 i.catalogid,
                 case
                     when Exists(select paymentodate from payentmethodvalidation q where q.paymentnoodate = o.ocardtype) AND NOT EXISTS(SELECT booked FROM bookedordersids m where CAST(m.booked AS int)=o.orderid) then sum(i.numitems)
                     when Exists(select paymentodate from payentmethodvalidation q where q.paymentodate = o.ocardtype) AND odate is not null AND NOT EXISTS(SELECT booked FROM bookedordersids m where CAST(m.booked AS int)=o.orderid) then sum(i.numitems)
                 else 0 end numitems,
                 sum(numitems) allitems 
             from 
                 "orders o
             inner join
                 "oitems i 
             on 
                 "i.orderid=o.orderid
             inner join
                 "products T1
             on 
                 "T1.catalogid = i.catalogid
             group by 
                 "i.catalogid, ocardtype, odate,o.orderid
         ) A
     ) B
     INNER JOIN
     (
         SELECT 
             catalogId, 
             ProcessedSucssessfully = 
                STUFF((SELECT ', ' + CAST( b.orderid as varchar(10))
                       FROM oitems b JOIN orders o ON b.orderid = o.orderid 
                       WHERE b.catalogId = a.catalogId 
                       AND  NOT EXISTS(SELECT booked FROM bookedordersids m where CAST(m.booked AS int)=o.orderid) AND (Exists(select paymentodate from payentmethodvalidation q where q.paymentnoodate = o.ocardtype) OR Exists(select paymentodate from payentmethodvalidation q where q.paymentodate = o.ocardtype) and o.odate is not null)
                       FOR XML PATH('')), 1, 2, ''), 
                           "NotProcessed = 
                 STUFF((SELECT ', ' + CAST( c.orderid as varchar(10))
                        FROM oitems c JOIN orders o ON c.orderId = o.orderid
                        WHERE c.catalogid = a.catalogid 
                        AND (o.ocardtype in ('mastercard') OR o.ocardtype is null) and o.odate is null
                        FOR XML PATH('')), 1, 2, '') 
         FROM 
             oitems a 
         GROUP BY 
             a.catalogid 
     )C
         ON 
             B.catalogid = C.catalogid 

the the result of this query you can see in the following image
enter image description here

you see those 2 circled rows, i want them to be in a one row that will only sum the numitems, the processed successfully value and all other values will be always the same for the records the share catalogid so no problem with them.

basicly the result row should have the sum of the numitem valuse in all rows that have the same catalogid

so how can i solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:10:34+00:00Added an answer on June 13, 2026 at 1:10 am

    If, as you mentioned, all the rest of the values are the same, the solution is simple:

    SELECT CATALOGID, 
           Sum(NUMITEMS), 
           ALLITEMS - NUMITEMS ignoreditems 
    FROM   (SELECT CATALOGID, 
                   NUMITEMS, 
                   ALLITEMS - NUMITEMS ignoreditems 
            FROM   (SELECT i.CATALOGID, 
                           CASE 
                             WHEN EXISTS(SELECT PAYMENTODATE 
                                         FROM   PAYENTMETHODVALIDATION q 
                                         WHERE  q.PAYMENTNOODATE = o.OCARDTYPE) 
                                  AND NOT EXISTS(SELECT BOOKED 
                                                 FROM   BOOKEDORDERSIDS m 
                                                 WHERE  Cast(m.BOOKED AS 
                                                        INT) = o.ORDERID) 
                           THEN 
                             Sum(i.NUMITEMS) 
                             WHEN EXISTS(SELECT PAYMENTODATE 
                                         FROM   PAYENTMETHODVALIDATION q 
                                         WHERE  q.PAYMENTODATE = o.OCARDTYPE) 
                                  AND ODATE IS NOT NULL 
                                  AND NOT EXISTS(SELECT BOOKED 
                                                 FROM   BOOKEDORDERSIDS m 
                                                 WHERE  Cast(m.BOOKED AS 
                                                        INT) = o.ORDERID) 
                           THEN 
                             Sum(i.NUMITEMS) 
                             ELSE 0 
                           END           numitems, 
                           Sum(NUMITEMS) allitems 
                    FROM   ORDERS o 
                           INNER JOIN OITEMS i 
                                   ON i.ORDERID = o.ORDERID 
                           INNER JOIN PRODUCTS T1 
                                   ON T1.CATALOGID = i.CATALOGID 
                    GROUP  BY i.CATALOGID, 
                              OCARDTYPE, 
                              ODATE, 
                              o.ORDERID) A) B 
           INNER JOIN (SELECT CATALOGID, 
                              ProcessedSucssessfully = Stuff( 
                              (SELECT ', ' + Cast( b.ORDERID 
                                      AS VARCHAR 
                                      (10)) 
                               FROM   OITEMS b 
                                      JOIN ORDERS o 
                                        ON 
                              b.ORDERID = o.ORDERID 
                               WHERE  b.CATALOGID = 
                                      a.CATALOGID 
                                      AND NOT 
                              EXISTS(SELECT BOOKED 
                                     FROM   BOOKEDORDERSIDS 
                                            m 
                                     WHERE 
                              Cast( 
                                    m.BOOKED AS 
                              INT) = o.ORDERID) 
                                      AND ( EXISTS 
                                      (SELECT PAYMENTODATE 
                                       FROM 
                                            PAYENTMETHODVALIDATION q 
                                                   WHERE 
                                      q.PAYMENTNOODATE = 
                                      o.OCARDTYPE) 
                                             OR EXISTS 
                                            (SELECT 
                                                PAYMENTODATE 
                                                       FROM 
                                                PAYENTMETHODVALIDATION 
                                                q 
                                                       WHERE 
                                            q.PAYMENTODATE = 
                      o.OCARDTYPE) 
                      AND o.ODATE IS NOT NULL ) 
                      FOR XML PATH('')), 1, 2, ''), 
                      NotProcessed = Stuff((SELECT ', ' + Cast( c.ORDERID AS VARCHAR 
                                                   (10)) 
                      FROM   OITEMS c 
                      JOIN ORDERS o 
                      ON c.ORDERID = o.ORDERID 
                      WHERE  c.CATALOGID = a.CATALOGID 
                      AND ( o.OCARDTYPE IN ( 'mastercard' ) 
                      OR o.OCARDTYPE IS NULL ) 
                      AND o.ODATE IS NULL 
                      FOR XML PATH('')), 1, 2, '') 
                       FROM   OITEMS a 
                       GROUP  BY a.CATALOGID)C 
                   ON B.CATALOGID = C.CATALOGID 
    GROUP  BY CATALOGID, 
              ALLITEMS - NUMITEMS 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I've got this query to get users by email, which is an unique
Hello everyone how can I get two values from different select boxes? I get
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello The following procedure will have to move all constraints from one table to
hello all i am working on a project in which i have a webpage
Hello I have following column in SSRS Report. Column Name(Title) Mehta, Natasha(18)----its Title+(count) value
Hello I want to get Accurate location so that i have used following link
Hello there am trying to save news tweets into three different array which are
Hello everybody, I'm stuck with a Doctrine join query. The system continues telling me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.