Solved

SQL Statement

Posted on 2011-02-10
7
341 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
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now