We help IT Professionals succeed at work.
Get Started

SQL 2005 - Exclude records from Select

266 Views
Last Modified: 2015-07-09
Experts,
I use the following query today
select
	REF,
	DATE,
	LEV1,
	LEV2,
	COALESCE(MAX(FROM_CODE),'UNR')as FROM_CODE,
	COALESCE(SUM(FROM_QTY), (SUM(TO_QTY)*-1))as FROM_QTY,
	COALESCE(MAX(TO_CODE),'UNR')as TO_CODE,
	COALESCE(SUM(TO_QTY), (SUM(FROM_QTY)*-1)) as TO_QTY	
	FROM BVF_947
	GROUP BY REF, DATE, LEV1, LEV2

Open in new window


Before the Group BY, each row will contain a FROM_CODE or a TO_CODE, but rarely both.
After the Group By each summarized record will always have both a FROM_CODE and TO_CODE

What I want to do, is exlcude any rows where the value is the same in both columns.  If we need to specify them there are only 4 values (UNR, QI, BLK, DIS or XX).  Can anyone help me do this?
Comment
Watch Question
Database and Application Developer
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE