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:

Professional Opinions
Ask a Question
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

troubleshooting Question

IF statement inside SQL columns list

Avatar of jammy-d0dger
jammy-d0dger asked on
Microsoft SQL ServerMicrosoft SQL Server 2005SQL
8 Comments1 Solution194 ViewsLast Modified:
Hi experts,
is it possible to do what I have attempted in the SQL attached?  I think the example speaks for itself, if there is only one item in an order the commission should be (item_count * 1.00), but if it's greater than one, the commission fee should be (item_count * 0.75).

Can I place 'if' in a sql query like this?
select A.orders_id, count(B.orders_id) As ItemCount, 
if ItemCount = 1 then (count(B.orders_id) * 1.00) else (count(B.orders_id) * .75) AS CommissionFee, d.manufacturers_id, d.manufacturers_name
from orders A, orders_products B, products C, manufacturers D
where date_purchased > '01/01/2008'
and a.orders_status in (4,8)
and a.orders_id = b.orders_id
and b.products_id = c.products_id
and c.manufacturers_id = d.manufacturers_id
group by a.orders_id, d.manufacturers_id, d.manufacturers_name
order by a.orders_id DESC