Solved

SQL Statement

Posted on 2011-02-10
7
345 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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