Search code examples
azure-synapse

IIF condition in Azure Synapse Derived Columns


In the 'Azure Synapse Derived Columns' section, I'm attempting to create a simple conditional expression using a CASE-WHEN or IF statement. However, it's not working as expected. What I'm trying:

iif(VERIFICATION_DATE != null, 'Y', null) iif(isnull(VERIFICATION_DATE), null, 'Y')

did not work, got mismatch type issue, i would like to understand why.

I just need to bring null when VERIFICATION_DATE is null and 'Y' when VERIFICATION_DATE is not null

iif(VERIFICATION_DATE != null, 'Y', null) iif(isnull(VERIFICATION_DATE), null, 'Y')


Solution

  • The reason you are getting type mismatch is because, null function gives null as return type whereas 'Y' is of string type. So, you convert null type to string inside if condition as below.

    iif(isNull(cc), toString(null()), 'Y')
    

    Output:

    enter image description here