Solved

SQL Statement

Posted on 2011-02-10
7
347 Views
Last Modified: 2012-05-11
I need to run a report to show me products where pack A quantity is different from pack B quantity. I can run a basic SQL statement that brings me all products and then I run a conditional formating to show me where quantity A is different from quantity B.

Is there a way I can write it straight in the SQL statement so it only gives me where the quantities differ for each product?
0
Comment
Question by:squirrelzan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 14

Assisted Solution

by:leoahmad
leoahmad earned 50 total points
ID: 34864579
select * from packa
minus
select * from packb;
0
 

Author Comment

by:squirrelzan
ID: 34864606
Just to confirm, I don't want to deduct pack A quantity from pack B quantity. I just need it to show me the products where pack A differs from pack B.
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 350 total points
ID: 34864632
Try this

select * from table where field1 <> field2

Sid
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 15

Assisted Solution

by:tim_cs
tim_cs earned 100 total points
ID: 34864647
SELECT
   *
FROM
   Table
WHERE
   PackA <> PackB
0
 

Author Closing Comment

by:squirrelzan
ID: 34864679
Thank you all for your help, especially Siddharthrout. Ran the statement and exactly what I needed.
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34864748
Check if this works for you:

SELECT *,
     CASE WHEN [PackAQty] = [PackBQty]
         THEN 'Equal'
         ELSE 'Different'
     END PackABQty
FROM [Products]

Open in new window

0
 

Author Comment

by:squirrelzan
ID: 34865287
That is a different way of doing it, it would work if I wanted to show all products.
Sid's solution above was more what I needed, but I could use wdosanjos too.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My experience with Windows 10 over a one year period and suggestions for smooth operation
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question