Solved

SQL Statement

Posted on 2011-02-10
7
351 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:Farah Mohammed
[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:Farah Mohammed
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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:Farah Mohammed
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:Farah Mohammed
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

Industry Leaders: 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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

617 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