Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Case statement & Having clause

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-10-22 : 22:55:46
Steve writes "I have a query where I need to have a "HAVING" clause in it.

The problem is, it has to check 3 fields depending on a condition being set.

The having clause I have is:

Having
(sum(sales_perform_yr_wholesaler2.prev_yr_ship_qty) > 0) or
case
when (sales_perform_yr_wholesaler2.sup_cust_cd is not null) and (sales_perform_yr_wholesaler2.sup_cust_cd <> ' ') then
(sales_perform_yr_wholesaler2.sup_cust_cd in ('R0787890','R0586227','R4226900'))
when (sales_perform_yr_wholesaler2.sum_cust_cd is not null) and (sales_perform_yr_wholesaler2.sum_cust_cd <> ' ') then
(sales_perform_yr_wholesaler2.sum_cust_cd in ('R0787890','R0586227','R4226900'))
else
(sales_perform_yr_wholesaler2.sold_to_cust_cd in ('R0787890','R0586227','R4226900'))
end

It needs to check for a ship Qty > 0 OR the input record having one of those customer numbers in one of the 3 fields I put into a customer number. The having clause uses the same logic I have in my select and groupby for selecting "customer code". The difference is where I have the cust_cd in a,b,c in the select, I have the proper cust_cd as the object.

I currently get an "incorrect syntax near the keyword ' in'. on the first when statement.

Can you do this?"
   

- Advertisement -