View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
dave k dave k is offline
external usenet poster
 
Posts: 21
Default SQL embedded "IF" statement

I tried this but can't get it to work. I am not sure if I have my syntax
correct or if this is not supported in Excel. I will keep trying. Do you
know if this is supported or not in Excel? Maybe only in SQL Server.

Thanks for the help.
Dave


"Fredrik Wahlgren" wrote:


"dave k" wrote in message
...
Is there a way to embed an if statement into a SQL select? I want to make

a
select output field = to one thing if a field is 1 and different if a

field
is < 1. I am using Excel to perform all queries. If possible it might

look
like this but I don't see if the IF is supported. If not, is there a
workaround?

SELECT F1, F2, IF(F11,F1*3,F1*2) FROM ATABLE

Thanks,
Dave


It's called a CASE expression in SQl Server:
http://www.craigsmullins.com/ssu_0899.htm

Your query would end up like this:

SELECT F1, F2,
F3 = CASE F1
WHEN F1 1 THEN F1 * 3 ELSE F1 * 2
END,
FROM ATABLE

/Fredrik

/Fredrik