none
How to convert Nested IIF Statment to SQL Server

    Question

  • IIf([A.programs] Like "MBI*",
    IIf([A.contractPurchDt]<#2/1/2011#,"Pre",
    IIf([A.bookState]='CA' And [A.contractPurchDt]>=#2/1/2011#,"CA_OK",
    IIf([A.bookState]='OR' And [A.contractPurchDt]>=#1/22/2012#,"OR_OK","N/A"))),"CLP_OK")

    Saturday, October 12, 2013 10:56 PM

Answers

  • Hi Ebed,

    The CASE statement would something along these lines. Please note that I haven't tested it but I know the syntax is correct. 

    CASE WHEN A.programs LIKE 'MBI*' THEN 
    	CASE WHEN A.contractPurchDt < '2/1/2011' THEN 'Pre'ELSE 
    		CASE WHEN A.bookState= 'CA' AND A.contractPurchDt >= '2/1/2011' THEN 'CA_OK' ELSE 
    			CASE WHEN A.bookState= 'OR' AND A.contractPurchDt >= '1/22/2012' THEN 'OR_OK' ELSE 'N/A' END
    		END
    	END
    ELSE 'CLP_OK' END
    Hope this helps!


    Shahfaisal Muhammed http://shahfaisalmuhammed.blogspot.com

    Sunday, October 13, 2013 12:43 AM

All replies