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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:19:41+00:00 2026-05-20T18:19:41+00:00

There has to be some way to re-write the folowing statement. It’s ugly, but

  • 0

There has to be some way to re-write the folowing statement. It’s ugly, but works. There has to be a better way. I would like to know so I don’t continue writing statements with nested selects.

The output would be:

H45_134, 190
H45_180, 143

Essentially, what I’m trying to get are the distinct devices and the number of times that device is used on an order. In the output above, “H45_134” is the device mfg number and 190 is the total number of times the device is used on the order. 190 is the sum of the line quantity on the order, but only where the device mfg number matches.

    SELECT distinct he1.[Mfg_Number] as HingeDeviceOneLocation, 
    (select sum(lineqty)
        FROM [MQPDatabase].[dbo].[Hinge_Edge] he2 inner join lineinfo li on li.ctr=he2.lineinfoctr 
            inner join order_header oh on oh.ctr=li.order_headerctr
            where location_1 >0 
                and location_2 =0 
                and location_3 = 0 
                and location_4=0 
                and location_5=0 
                and oh.jobnum='T35204D' 
                and he1.mfg_number=he2.mfg_number) as DeviceQty
  FROM [MQPDatabase].[dbo].[Hinge_Edge] he1 inner join lineinfo li on li.ctr=he1.lineinfoctr 
    inner join order_header oh on oh.ctr=li.order_headerctr
    where location_1 >0 
        and location_2 =0 
        and location_3 = 0 
        and location_4=0 
        and location_5=0 
        and oh.jobnum='T35204D'
  • 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-20T18:19:42+00:00Added an answer on May 20, 2026 at 6:19 pm

    Give this a try.

    SELECT he1.[Mfg_Number] as HingeDeviceOneLocation, sum(lineqty) as DeviceQty
      FROM [MQPDatabase].[dbo].[Hinge_Edge] he1 
        inner join lineinfo li on li.ctr=he1.lineinfoctr 
        inner join order_header oh on oh.ctr=li.order_headerctr
        where location_1 >0 
            and location_2 =0 
            and location_3 = 0 
            and location_4=0 
            and location_5=0 
            and oh.jobnum='T35204D'
      GROUP BY he1.[Mfg_Number]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the window.open() object has some funky parameter list... is there a way to do
Is there some standard way or has anyone written something that allows you to
Is there a good profiler for javascript? I know that firebug has some support
I know there are some ways to get notified when the page body has
I am using Specflow (http://specflow.org/) to write some integration tests and I would like
There has been some talk of Website performance monitoring tools and services on stackoverflow,
Recently there has been quite some hype around all the different mocking frameworks in
I realize that since UNIX sockets are platform-specific, there has to be some non-Java
Is there a good application (that has some kind of gui) for testing memory
In my graphics application, there is canvas area that has some graph. The scrollbars

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.