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

  • Home
  • SEARCH
  • 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 6803501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:21:08+00:00 2026-05-26T19:21:08+00:00

I have been asking questions to get the final results for a SQL query

  • 0

I have been asking questions to get the final results for a SQL query that my company has asked for. I finally got the end result that I was initially asked for, but they want more.

My company wants me to make the query show only values with movement (Sold, Purchased or Adjusted). I don’t know how to make this work, or where to look.

SET ARITHABORT OFF
SET ANSI_WARNINGS OFF
SELECT
[UPC]=t1.F01,
COALESCE((SELECT SUM (COALESCE (X.F64, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2011-10-1' and X.F254<='2011-11-11') and (X.F1034 = 3) AND X.F01 = T1.F01 Group by X.F01,X.F1034),0) AS [Total QTY Sold],
COALESCE((SELECT SUM (COALESCE (X.F65, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2011-10-1' and X.F254<='2011-11-11') and (X.F1034 = 3) AND X.F01 = T1.F01 Group by X.F01,X.F1034),0) AS [Total Amount Sold],
COALESCE((SELECT SUM (COALESCE (X.F1301, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2011-10-1' and X.F254<='2011-11-11') and (X.F1034 = 3) AND X.F01 = T1.F01 Group by X.F01,X.F1034),0) AS [Total Cost Sold],
[Margin]=COALESCE(((1-(COALESCE((SELECT SUM (COALESCE (X.F1301, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2011-10-1' and X.F254<='2011-11-11') and (X.F1034 = 3) AND X.F01 = T1.F01 Group by X.F01,X.F1034),0)/COALESCE((SELECT SUM (COALESCE (X.F65, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2011-10-1' and X.F254<='2011-11-11') and (X.F1034 = 3) AND X.F01 = T1.F01 Group by X.F01,X.F1034),0)))*100),0),
COALESCE((SELECT SUM (COALESCE (X.F64, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2011-10-1' and X.F254<='2011-11-11') and X.F1034 = 8201 AND X.F01 = T1.F01 Group by X.F01,X.F1034),0) AS [QTY Purchased],
COALESCE((SELECT SUM (COALESCE (X.F65, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2011-10-1' and X.F254<='2011-11-11') and X.F1034 = 8201 AND X.F01 = T1.F01 group by X.F01,X.F1034),0) AS [Amount Purchased],
COALESCE((SELECT SUM (COALESCE (X.F64, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2011-10-1' and X.F254<='2011-11-11') and X.F1034 = 8801 AND X.F01 = T1.F01 Group by X.F01,X.F1034),0) AS [QTY Adjusted],
COALESCE((SELECT SUM (COALESCE (X.F65, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2011-10-1' and X.F254<='2011-11-11') and X.F1034 = 8801 AND X.F01 = T1.F01 Group by X.F01,X.F1034),0) AS [Amount Adjusted],
((COALESCE((SELECT SUM (COALESCE (X.F64, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2010-1-1' and X.F254<='2011-11-11') and X.F1034 = 8201 AND X.F01 = T1.F01 Group by X.F01,X.F1034),0)) - (COALESCE((SELECT SUM (COALESCE (X.F64, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2010-1-1' and X.F254<='2011-11-11') and X.F1034 = 3 AND X.F01 = T1.F01 Group by X.F01,X.F1034),0)) + (COALESCE((SELECT SUM (COALESCE (X.F64, 0)) FROM [STORESQL].[dbo].[RPT_ITM_D] X WHERE (X.F254>='2010-1-1' and X.F254<='2011-11-11') and X.F1034 = 8801 AND X.F01 = T1.F01 Group by X.F01,X.F1034),0))) AS [Current Inventory]

FROM [STORESQL].[dbo].[COST_TAB] t1
where F27='119828' and (F90 is null or F90=1)
group by T1.F01
order by t1.[F01]

A spinet of the results is as follows (shortened headers to make it fit):

UPC  QTY_S  AMT_S  Cost_S  Margin  QTY_P  AMT_P  QTY_A  AMT_A  Inv
123  1      61.19  54      11.75   0      0      0      0      0
456  0      0      0       0       0      0      0      0      5
789  39     38.61  19.5    49.49   2600   1300   0      0      2559
012  0      0      0       0       0      0      0      0      0

The results that I need are as follows:

UPC  QTY_S  AMT_S  Cost_S  Margin  QTY_P  AMT_P  QTY_A  AMT_A  Inv
123  1      61.19  54      11.75   0      0      0      0      0
789  39     38.61  19.5    49.49   2600   1300   0      0      2559

As you may have noticed, Regardless of value in UPC and Inv, I need the query to result in only items with movement.

Thank you in advance

  • 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-26T19:21:08+00:00Added an answer on May 26, 2026 at 7:21 pm

    do this:

    SELECT
        *
        FROM (
                --your query here (remove order by)
             ) dt
        WHERE dt.QTY_S!=0
        ORDER BY dt.UPC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have been asking questions here trying to get the answer for myself
I have been asking in previous questions about how to get multiple string inputs
Hey guys, lately I have been asking quite a few questions about memory management
I'm really sorry, I realize there have been several questions asked about cocos2d touch
I've been asking a series of evolving questions regarding my Android project that continually
Ok, So i know this questions has been asked. and everything i read has
For the last two days, I have been asking questions on rank queries in
I'm 10000000% sure that this question has been asked before, however, the majority of
Interview Question I have been asked this question in an interview, and the answer
This question has been asked before, but I would like a little more detail

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.