Link to home
Start Free TrialLog in
Avatar of GPSPOW
GPSPOWFlag for United States of America

asked on

Convert Excel formula to SQL case statement

Can someone help me convert the following Excel IF statement to either a SQL case statement or MS-Query SQL statement:

CurMonth

=IF(MONTH(getdate())=1,
IF(MO=12,
IF(YR=YEAR(getdate())-1,1,0),0),
IF(MO=MONTH(getdate())-1,
IF(YR=YEAR(getdate()),1,0)))


CurYear

=IF(MONTH(getdate())=1,
IF(MO<=12,
IF(YR=YEAR(getdate())-1,1,0),0),
IF(MO<=MONTH(getdate())-1,
IF(YR=YEAR(getdate()),1,0)))


PriorYear

=IF(MONTH(getdate())=1,
IF(MO<=12,
IF(YR=YEAR(getdate())-2,1,0),0),
IF(MO<=MONTH(getdate())-1,
IF(YR=YEAR(getdate())-1,1,0)))


Thanks

Glen
Avatar of Simon
Simon
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi Glen, the statements in your question look like a mixture of Excel and TSQL. Can you explain a bit more about what you'd like to achieve and post a few rows of sample data.
Avatar of GPSPOW

ASKER

I've requested that this question be deleted for the following reason:

Was able to convert Excel IF statement to a SQL query.

Thanks for reviewing it.

Glen
ASKER CERTIFIED SOLUTION
Avatar of GPSPOW
GPSPOW
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial