GPSPOW
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
CurMonth
=IF(MONTH(getdate())=1,
IF(MO=12,
IF(YR=YEAR(getdate())-1,1,
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,
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,
IF(MO<=MONTH(getdate())-1,
IF(YR=YEAR(getdate())-1,1,
Thanks
Glen
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.
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
Was able to convert Excel IF statement to a SQL query.
Thanks for reviewing it.
Glen
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.