We help IT Professionals succeed at work.
Get Started

Sum - Case when

Last Modified: 2012-05-05
The results shown in the Excel file : text.xls

Have a table tbl_testingfreight :
The result is the first tab of the Excel sheet (Actual Data)
After running the below script I get the results showed in the second tab (Result based on the query)

I am trying to do a SQL case when , but not able to see the result as needed
The final result needs tto be as shown in the tab (Results required)

The conditions are:
when the VndrNum = 359958 and  OpCo = 177 for that SUVCVndrNum, ItemNum --------  need to sum up the [Freight Cost / Case ($)] jus t as highlighted.

How can i apply this condion in the below query:

select TOP 100 PERCENT
	,sum(Cases) [Case Volume]	
	,sum(FOB) [COGS ($)]
	,sum(isnull(FrtPerCase, 0)*Cases) [Freight Cost ($)]
	,sum(isnull(LEIPerCase, 0)*Cases) [LEI ($)]
	,max(isnull(FrtPerCase, 0)) [Freight Cost / Case ($)]
	,max(isnull(LEIPerCase, 0)) [LEI ($) / Case]
	tbl_testingfreight d
	left outer join test.dbo.[OpCo Locations] o
		on d.OpCo  =  o.OpCo
	cross join (select distinct sourcinginitiative 
			from [freightPO-OPCO]) si
	SourcedCases  >  0
group by
order by

Open in new window

Watch Question
Chief Technology Officer
Most Valuable Expert 2011
This problem has been solved!
Unlock 1 Answer and 11 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