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 1114029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:56:49+00:00 2026-05-17T02:56:49+00:00

Query: ;WITH SuperSelect AS ( SELECT DISTINCT DropshipPackinglist.CaseNumber AS ‘CASE NO.’, DropshipPackinglist.Quantity AS ‘QTY’

  • 0

Query:

;WITH SuperSelect AS (
 SELECT DISTINCT
        DropshipPackinglist.CaseNumber AS 'CASE NO.', 
        DropshipPackinglist.Quantity AS 'QTY'
   FROM DropshipPackinglist 
   JOIN HuaweiDescription ON DropshipPackinglist.ItemNumber = HuaweiDescription.ItemNumber
  WHERE (DropshipPackinglist.BatchCode ='0003721008190AHWA01KG'))
SELECT COUNT(A) as PALLET ,
       [TOTAL VOLUME (MM3)],
       CASE
         WHEN [TOTAL VOLUME (MM3)] = '1090x730x1460' THEN Count(A) * 1.09*0.73*1.46
         WHEN [TOTAL VOLUME (MM3)] = '1090x730x1230' THEN Count(A) * 1.09*0.73*1.23
         WHEN [TOTAL VOLUME (MM3)] = '1090x730x1000' THEN Count(A) * 1.09*0.73*1.00
         WHEN [TOTAL VOLUME (MM3)] = '1090x730x780' THEN Count(A) *  1.09*0.73*0.78
         WHEN [TOTAL VOLUME (MM3)] = '1090x730x570' THEN Count(A) *  1.09*0.73*0.57
         WHEN [TOTAL VOLUME (MM3)] = '1090x730x350' THEN Count(A) *  1.09*0.73*0.35
         ELSE 'Unknown' 
       END as 'WEIGHT'
FROM (SELECT DISTINCT 
                 SUM([QTY]) OVER (partition BY ss.[CASE NO.]) as A,
                 CASE 
                   WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 31 
                    AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 36 THEN '1090x730x1460' 
                   WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 25 
                    AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 30 THEN '1090x730x1230'
                   WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 19 
                    AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 24 THEN '1090x730x1000'
                   WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 13 
                    AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 18 THEN '1090x730x780' 
                   WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 7 
                    AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 11 THEN '1090x730x570' 
                   WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 1 
                    AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 6 THEN '1090x730x350'
                   ELSE 'Unkown' 
                 END AS 'TOTAL VOLUME (MM3)'
            FROM SuperSelect ss) AS CountPallet
GROUP BY [TOTAL VOLUME (MM3)]

I have this Result:

PALLET  TOTAL VOLUME (MM3)  WEIGHT
--------------------------------------
2       1090x730x1230       1.957422
1       1090x730x1460       1.161722

My Problem is that I also need to add a column to compute the sum of WEIGHT.

Sample Result:

PALLET  TOTAL VOLUME (MM3)  WEIGHT    TOTALWEIGHT
---------------------------------------------------
2       1090x730x1230       1.957422  3.119144
1       1090x730x1460       1.161722  3.119144
  • 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-05-17T02:56:50+00:00Added an answer on May 17, 2026 at 2:56 am

    You can use SUM ... OVER()

    As the definition of weight is quite lengthy that and your derived table could go into other CTEs.

    Something like

    ;WITH 
    SuperSelect AS (SELECT DISTINCT... '0003721008190AHWA01KG'),
    CountPallet AS (SELECT... FROM SuperSelect ss),
    NewCTE AS (SELECT COUNT(A) ... GROUP BY [TOTAL VOLUME (MM3)])
    
    select PALLET, [TOTAL VOLUME (MM3)], isnull(WEIGHT,'Unknown') AS WEIGHT,
    SUM(WEIGHT) OVER() AS TOTALWEIGHT
    from NewCTE
    

    You would need to get rid of your else in the case expression to ensure weight was numeric.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a query to fetch results for all the values in a
(please excuse that I didn't use aliases). I would like my query output to

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.